Skip to content

Commit

Permalink
refactor(PHP): use PSR-12
Browse files Browse the repository at this point in the history
Follow modern coding standard (#222)

* Follow modern coding standard

PSR2 is ancient.

* style(php): fix linting errors

Co-authored-by: Dominik Tränklein <[email protected]>
  • Loading branch information
szepeviktor and domtra authored Feb 26, 2020
1 parent 0b5a4e7 commit c9a369d
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions Components/FeatureAdminComponentScreenshots/functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Flynt\Components\FeatureAdminComponentScreenshots;

use Flynt\ComponentManager;
Expand Down
1 change: 1 addition & 0 deletions inc/acf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Flynt\Acf;

use Flynt\Utils\Options;
Expand Down
4 changes: 3 additions & 1 deletion inc/componentLogServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Usage:
* Add get param `log` to url e.g. `http://localhost:3000/?log` and all the data will be output to via console.log in the dev tools in the browser.
*/

namespace Flynt\ComponentLogServer;

use Flynt;
Expand All @@ -21,7 +22,8 @@

function addDebugInfo($data, $componentName)
{
if (!defined(__NAMESPACE__ . '\COMPONENT_WHITELIST') ||
if (
!defined(__NAMESPACE__ . '\COMPONENT_WHITELIST') ||
in_array($componentName, Flynt\ComponentLogServer\COMPONENT_WHITELIST)
) {
consoleDebug([
Expand Down
4 changes: 2 additions & 2 deletions inc/customPostTypes/example.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Flynt\CustomPostTypes;

/**
* This is an example file showcasing how you can add custom post types to your Flynt theme.
*
* For a full list of parameters see https://developer.wordpress.org/reference/functions/register_post_type/ or use https://generatewp.com/post-type/ to generate the code for you.
*/

namespace Flynt\CustomPostTypes;

// function registerExamplePostType()
// {
// $labels = [
Expand Down
4 changes: 2 additions & 2 deletions inc/customTaxonomies/example.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Flynt\CustomTaxonomies;

/**
* This is an example file showcasing how you can add custom taxonomies to your Flynt theme.
*
* For a full list of parameters see https://developer.wordpress.org/reference/functions/register_taxonomy/ or use https://generatewp.com/taxonomy/ to generate the code for you.
*/

namespace Flynt\CustomTaxonomies;

// function registerExampleTaxonomy()
// {
// $labels = [
Expand Down
2 changes: 2 additions & 0 deletions inc/fieldVariables.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

/**
* Defines field variables to be used across multiple components.
*/

namespace Flynt\FieldVariables;

function getTheme()
Expand Down
1 change: 1 addition & 0 deletions inc/hideProtectedPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Hide password protected posts from listings when using the loop or `get_posts`.
*/

namespace Flynt\HideProtectedPosts;

add_action('pre_get_posts', function ($query) {
Expand Down
2 changes: 2 additions & 0 deletions inc/jquery.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* Loads jQuery before the closing body tag by default. Can be overwritten if there is a script in the head with jQuery as a dependency.
*
* If the Asset utility has `loadFromCdn` set to true, it will load from Google's CDN falling back to the default WordPress script. This setting can be changed in the `lib/Init.php` file inside the `initTheme` function.
*/

namespace Flynt\Jquery;

use Flynt\Utils\Asset;
Expand Down
2 changes: 2 additions & 0 deletions inc/mimeTypes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

/**
* Adds SVG to the mime types supported (useful for gallery uploads in the WP Backend).
*/

namespace Flynt\MimeTypes;

add_filter('upload_mimes', function ($mimes) {
Expand Down
2 changes: 2 additions & 0 deletions inc/removeEditor.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

/**
* Removes `the_content` area (editor) from the Wordpress backend, since Flynt uses ACF.
*/

namespace Flynt\RemoveEditor;

add_action('init', function () {
Expand Down
14 changes: 8 additions & 6 deletions inc/theContentFix.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ function isShortcodeAndDoesNotMatchId($postContent, $postId)
}

add_filter('wp_insert_post_data', function ($data, $postArr) {
if (in_array(
$postArr['post_type'],
[
if (
in_array(
$postArr['post_type'],
[
'revision',
'nav_menu_item',
'attachment',
'customize_changeset',
'custom_css'
]
)) {
'custom_css',
]
)
) {
return $data;
}
// check if no content was saved before, or if there is a flyntTheContent shortcode but the id does not match the post id
Expand Down
2 changes: 2 additions & 0 deletions inc/timberDynamicResize.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** */

namespace Flynt\TimberDynamicResize;

use Flynt\Utils\TimberDynamicResize;
Expand Down
2 changes: 2 additions & 0 deletions inc/timberLoader.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* - Enables rendering with Timber and Twig.
* - Converts ACF Images to Timber Images if ACF is enabled.
* - Convert ACF Field of type post_object to a Timber\Post and add all ACF Fields of that Post
*/

namespace Flynt\TimberLoader;

use Flynt\Utils\TwigExtensionFlynt;
Expand Down
1 change: 1 addition & 0 deletions inc/tinyMce.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* See the TinyMce documentation for more information: https://www.tiny.cloud/docs/
*
*/

namespace Flynt\TinyMce;

// First Toolbar
Expand Down
2 changes: 2 additions & 0 deletions inc/yoastToBottom.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

/**
* Moves the Yoast SEO plugin box to the bottom of the backend interface.
*/

namespace Flynt\YoastToBottom;

function init()
Expand Down
2 changes: 2 additions & 0 deletions inc/youtubeNoCookieEmbed.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

/**
* Changes oEmbed YouTube URLs from youtube.com to youtube-nocookie.com in favor of GDPR.
*/

namespace Flynt\YoutubeNoCookieEmbed;

use Flynt\Utils\Oembed;
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Timber\Timber;
use Timber\PostQuery;
use Flynt\Utils\Options;

use const Flynt\Archives\POST_TYPES;

$context = Timber::get_context();
Expand Down
2 changes: 1 addition & 1 deletion lib/ComponentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ComponentManager
public static function getInstance()
{
if (null === self::$instance) {
self::$instance = new self;
self::$instance = new self();
}
return self::$instance;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Utils/AdminNoticeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AdminNoticeManager
public static function getInstance()
{
if (null === self::$instance) {
self::$instance = new self;
self::$instance = new self();
}
return self::$instance;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Utils/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ protected static function add($funcType, $options)

// allow external urls
$path = $options['path'];
if (!(StringHelpers::startsWith('http://', $path))
if (
!(StringHelpers::startsWith('http://', $path))
&& !(StringHelpers::startsWith('https://', $path))
&& !(StringHelpers::startsWith('//', $path))
) {
Expand All @@ -221,14 +222,16 @@ protected static function add($funcType, $options)
$fileExists = true;
}

if ('script' === $options['type']
if (
'script' === $options['type']
&& true === self::$loadFromCdn
&& !empty($options['cdn'])
&& !empty($options['cdn']['check'])
&& !empty($options['cdn']['url'])
) {
// if the script isn't registered or enqueued yet
if (!wp_script_is($options['name'], 'registered')
if (
!wp_script_is($options['name'], 'registered')
&& !wp_script_is($options['name'], 'enqueued')
) {
$localPath = $path;
Expand Down
2 changes: 1 addition & 1 deletion lib/Utils/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function pp($data, $postpone = true)
public static function consoleDebug($data, $postpone = true, $title = 'PHP', $logType = 'log')
{
if (in_array($logType, ['log', 'error', 'trace'])) {
$title .= '(' . self::getCallerFile(2) .'):';
$title .= '(' . self::getCallerFile(2) . '):';
$type = gettype($data);
$output = json_encode($data);
$result = "<script>console.{$logType}('{$title}', '({$type})', {$output});</script>\n";
Expand Down
6 changes: 4 additions & 2 deletions lib/Utils/TimberDynamicResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ protected function generateImage($url, $w, $h, $crop, $force = false)

if ($this->webpEnabled) {
$fileinfo = pathinfo($resizedUrl);
if (in_array($fileinfo['extension'], [
if (
in_array($fileinfo['extension'], [
'jpeg',
'jpg',
'png',
])) {
])
) {
ImageHelper::img_to_webp($resizedUrl);
}
}
Expand Down
2 changes: 1 addition & 1 deletion phpcs.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
<!-- Exclude Warnings -->
<arg value="n"/>

<rule ref="PSR2"/>
<rule ref="PSR12"/>
</ruleset>

0 comments on commit c9a369d

Please sign in to comment.