Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Introduce phpstan #391

Draft
wants to merge 14 commits into
base: feature/documentation
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 4 additions & 0 deletions .phpstan/class-aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

class WPCOM_VIP_CLI_Command {}
class WP_CLI_Command {}
7 changes: 7 additions & 0 deletions .phpstan/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

define( 'WPCOM_IS_VIP_ENV', '' );
define( 'WPINC', '' );
define( 'LOGGED_IN_COOKIE', '' );
define( 'CLDN_URL', '' );
define( 'CLDN_PATH', '' );
4 changes: 4 additions & 0 deletions .phpstan/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

function wpcom_vip_attachment_url_to_postid( $file ) {}
function wc_get_product() {}
53 changes: 28 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"name": "cloudinary/cloudinary-image-management-and-manipulation-in-the-cloud-cdn",
"homepage": "https://wordpress.org/plugins/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"require": {
"ext-json": "*"
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"automattic/vipwpcs": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0"
},
"config": {
"platform": {
"php": "5.6.20"
}
},
"scripts": {
"lint": [
"phpcs --ignore=*js/*"
],
"fix": [
"phpcbf --ignore=*js/*"
]
}
"name": "cloudinary/cloudinary-image-management-and-manipulation-in-the-cloud-cdn",
"homepage": "https://wordpress.org/plugins/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/",
"description": "Cloudinary is a cloud service that offers a solution to a web application's entire image and video management pipeline.",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"require": {
"ext-json": "*"
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"automattic/vipwpcs": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"szepeviktor/phpstan-wordpress": "^0.7.5",
"phpstan/extension-installer": "^1.1"
},
"config": {
"platform": {
"php": "7.1"
}
},
"scripts": {
"lint": [
"phpcs --ignore=*js/*"
],
"fix": [
"phpcbf --ignore=*js/*"
]
}
}
352 changes: 335 additions & 17 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
2 changes: 1 addition & 1 deletion php/class-connect.php
Original file line number Diff line number Diff line change
@@ -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 ) ) {
9 changes: 9 additions & 0 deletions php/class-rest-api.php
Original file line number Diff line number Diff line change
@@ -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;
}

/**
1 change: 1 addition & 0 deletions php/connect/class-api.php
Original file line number Diff line number Diff line change
@@ -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 );
4 changes: 2 additions & 2 deletions php/media/class-video.php
Original file line number Diff line number Diff line change
@@ -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 );
}
3 changes: 2 additions & 1 deletion php/templates/connection-string.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
<p>
<?php
printf(
wp_kses_post( 'After creating your %s:', 'cloudinary' ),
// translators: Link to create a Cloudinary account.
wp_kses_post( __( 'After creating your %s:', 'cloudinary' ) ),
sprintf(
// translators: Link to create a Cloudinary account.
esc_html__( '%1$sCloudinary account%2$s', 'cloudinary' ),
5 changes: 1 addition & 4 deletions php/ui/component/class-react.php
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@

namespace Cloudinary\UI\Component;

use Cloudinary\Media\Gallery;
use function Cloudinary\get_plugin_instance;

/**
* Frame Component to render components only.
*
@@ -79,7 +76,7 @@ protected function scripts( $struct ) {
'ver' => $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;
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -33,4 +33,5 @@
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/build/</exclude-pattern>
<exclude-pattern>.phpstan/</exclude-pattern>
</ruleset>
21 changes: 21 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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/*'