diff --git a/.gitignore b/.gitignore index 6c619edfd..e618a01ff 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ coverage/html/ .vscode cloudinary-image-management-and-manipulation-in-the-cloud-cdn cloudinary-image-management-and-manipulation-in-the-cloud-cdn.zip + +# phpstan +phpstan/ diff --git a/.phpstan/class-aliases.php b/.phpstan/class-aliases.php new file mode 100644 index 000000000..6d98fcbd3 --- /dev/null +++ b/.phpstan/class-aliases.php @@ -0,0 +1,4 @@ +=5.3", - "squizlabs/php_codesniffer": "^2 || ^3 || 4.0.x-dev" + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" }, "require-dev": { "composer/composer": "*", @@ -118,28 +123,181 @@ "stylecheck", "tests" ], - "time": "2020-06-25T14:57:39+00:00" + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v5.7.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "69baf30e7c92f149526da950a68222af05f7bc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/69baf30e7c92f149526da950a68222af05f7bc67", + "reference": "69baf30e7c92f149526da950a68222af05f7bc67", + "shasum": "" + }, + "replace": { + "giacocorsiglia/wordpress-stubs": "*" + }, + "require-dev": { + "giacocorsiglia/stubs-generator": "^0.5.0", + "php": "~7.1" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.7.0" + }, + "time": "2021-03-10T10:29:23+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/66c7adc9dfa38b6b5838a9fb728b68a7d8348051", + "reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1 || ^2.0", + "php": "^7.1 || ^8.0", + "phpstan/phpstan": ">=0.11.6" + }, + "require-dev": { + "composer/composer": "^1.8", + "phing/phing": "^2.16.3", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.1.0" + }, + "time": "2020-12-13T13:06:13+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "0.12.82", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3920f0fb0aff39263d3a4cb0bca120a67a1a6a11", + "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.82" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-03-19T06:08:17+00:00" }, { "name": "sirbrillig/phpcs-variable-analysis", - "version": "v2.9.0", + "version": "v2.11.0", "source": { "type": "git", "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "ff54d4ec7f2bd152d526fdabfeff639aa9b8be01" + "reference": "e76e816236f401458dd8e16beecab905861b5867" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/ff54d4ec7f2bd152d526fdabfeff639aa9b8be01", - "reference": "ff54d4ec7f2bd152d526fdabfeff639aa9b8be01", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/e76e816236f401458dd8e16beecab905861b5867", + "reference": "e76e816236f401458dd8e16beecab905861b5867", "shasum": "" }, "require": { "php": ">=5.4.0", - "squizlabs/php_codesniffer": "^3.1" + "squizlabs/php_codesniffer": "^3.5" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4 || ^0.5 || ^0.6", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "limedeck/phpunit-detailed-printer": "^3.1 || ^4.0 || ^5.0", "phpstan/phpstan": "^0.11.8", "phpunit/phpunit": "^5.0 || ^6.5 || ^7.0 || ^8.0", @@ -166,7 +324,12 @@ } ], "description": "A PHPCS sniff to detect problems with variables.", - "time": "2020-10-07T23:32:29+00:00" + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2021-03-09T22:32:14+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -217,8 +380,156 @@ "phpcs", "standards" ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, "time": "2020-10-23T02:01:07+00:00" }, + { + "name": "symfony/polyfill-php73", + "version": "v1.22.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a678b42e92f86eca04b7fa4c0f6f19d097fb69e2", + "reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" + }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v0.7.5", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "90cf3c6a225a633889b1b3a556816911f42de4f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/90cf3c6a225a633889b1b3a556816911f42de4f7", + "reference": "90cf3c6a225a633889b1b3a556816911f42de4f7", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0", + "phpstan/phpstan": "^0.12.26", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^1.8.6", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^0.12", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v0.7.5" + }, + "funding": [ + { + "url": "https://www.paypal.me/szepeviktor", + "type": "custom" + } + ], + "time": "2021-03-19T21:23:23+00:00" + }, { "name": "wp-coding-standards/wpcs", "version": "2.3.0", @@ -263,6 +574,11 @@ "standards", "wordpress" ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, "time": "2020-05-13T23:57:56+00:00" } ], @@ -271,10 +587,12 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-json": "*" + }, "platform-dev": [], "platform-overrides": { - "php": "5.6.20" + "php": "7.1" }, - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/package.json b/package.json index 5a8e66f2b..8860cf2ac 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "deploy-assets": "grunt deploy-assets", "postinstall": "composer install", "readme": "composer readme", - "build:docs": "rm -rf docs && jsdoc -c hookdoc-conf.json php ui-definitions cloudinary.php" + "build:docs": "rm -rf docs && jsdoc -c hookdoc-conf.json php ui-definitions cloudinary.php", + "phpstan": "vendor/bin/phpstan analyze --memory-limit=-1" }, "husky": { "hooks": { diff --git a/php/class-connect.php b/php/class-connect.php index 9c374f664..a1e15928a 100644 --- a/php/class-connect.php +++ b/php/class-connect.php @@ -692,7 +692,7 @@ public function upgrade_connection( $old_version ) { if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) { return; // Not setup at all, abort upgrade. } - } elseif ( version_compare( $old_version, '2.0.0', '<' ) ) { + } else { // from V1 to V2. $cld_url = get_option( self::META_KEYS['url'], null ); if ( empty( $cld_url ) ) { diff --git a/php/class-rest-api.php b/php/class-rest-api.php index 88b3a8ffe..6cb401832 100644 --- a/php/class-rest-api.php +++ b/php/class-rest-api.php @@ -14,6 +14,13 @@ class REST_API { const BASE = 'cloudinary/v1'; + /** + * Holds the plugin instance. + * + * @var Plugin Instance of the global plugin. + */ + public $plugin; + /** * Plugin REST API endpoints. * @@ -28,6 +35,8 @@ class REST_API { */ public function __construct( Plugin $plugin ) { add_action( 'rest_api_init', array( $this, 'rest_api_init' ), PHP_INT_MAX ); + + $this->plugin = $plugin; } /** diff --git a/php/connect/class-api.php b/php/connect/class-api.php index cc66d1094..5dad468de 100644 --- a/php/connect/class-api.php +++ b/php/connect/class-api.php @@ -307,6 +307,7 @@ public function get_asset_details( $public_id, $type ) { * @return array|\WP_Error */ public function upload_large( $attachment_id, $args ) { + $result = array(); // Ensure we have the right file. if ( empty( $args['file'] ) ) { $args['file'] = get_attached_file( $attachment_id ); diff --git a/php/media/class-video.php b/php/media/class-video.php index 9f23e2a04..d68f75793 100644 --- a/php/media/class-video.php +++ b/php/media/class-video.php @@ -216,10 +216,10 @@ public function admin_enqueue_scripts() { */ public function filter_video_block_render_block( $block_content, array $block ) { if ( 'core/video' === $block['blockName'] ) { - remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10, 2 ); + remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10 ); $filtered_block = $this->filter_video_block_pre_render( $block, $block ); - $block_content = render_block( $filtered_block ); + $block_content = render_block( $filtered_block ); add_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10, 2 ); } diff --git a/php/templates/connection-string.php b/php/templates/connection-string.php index a8c817c00..363b6afe2 100644 --- a/php/templates/connection-string.php +++ b/php/templates/connection-string.php @@ -11,7 +11,8 @@

$this->setting->get_root_setting()->get_param( 'version' ), 'in_footer' => true, ); - $this->script = wp_parse_args( $this->setting->get_param( 'script' ), $script_default ); + $this->script = wp_parse_args( $this->setting->get_param( 'script' ), $script_default ); } return $struct; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 3bff13338..64e262a1a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -33,4 +33,5 @@ /node_modules/ /vendor/ /build/ + .phpstan/ diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..0aeafe4da --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,21 @@ +parameters: + level: 1 + tmpDir: phpstan + paths: + - cloudinary.php + - instance.php + - php + - ui-definitions + bootstrapFiles: + - .phpstan/class-aliases.php + - .phpstan/constants.php + - .phpstan/functions.php + ignoreErrors: + - '~WP_CLI~' + - '~stop_the_insanity~' + - '~^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$~' + - + message: '~^Variable \$this might not be defined.$~' + paths: + - 'php/templates/*' + - 'ui-definitions/*'