Check also tasks and tools with code sniffer

[MAILPOET-2429]
This commit is contained in:
Jan Jakeš
2019-10-10 13:39:12 +02:00
committed by Jack Kitterhing
parent cc62da6cb3
commit 7ecabdba3a
14 changed files with 88 additions and 64 deletions

View File

@ -7,6 +7,7 @@ if (!file_exists($path)) {
$filename = $path . '/mailpoet-' . microtime(true) . '.txt'; $filename = $path . '/mailpoet-' . microtime(true) . '.txt';
$file_handle = fopen($filename, "w"); $file_handle = fopen($filename, "w");
// phpcs:ignore Squiz.PHP.DiscouragedFunctions
$call_arguments = print_r($argv, true) . "\n"; $call_arguments = print_r($argv, true) . "\n";
fwrite($file_handle, $call_arguments); fwrite($file_handle, $call_arguments);

View File

@ -383,7 +383,24 @@ class RoboFile extends \Robo\Tasks {
->taskExec($task) ->taskExec($task)
->rawArg('--runtime-set testVersion 5.6-7.3') ->rawArg('--runtime-set testVersion 5.6-7.3')
->rawArg('-l .') ->rawArg('-l .')
// PHP >= 7.2 for dev tools, etc.
->taskExec($task)
->rawArg('--runtime-set testVersion 7.2-7.3')
->arg('--ignore=' . implode(',', [
'prefixer/build',
'prefixer/vendor',
'tasks/code_sniffer/vendor',
'tasks/makepot',
'tools/vendor',
])
) )
->args([
'.circleci',
'prefixer',
'tasks',
'tools',
])
->run(); ->run();
} }

View File

@ -44,7 +44,7 @@ $replacements = [
[ [
'file' => '../vendor-prefixed/twig/twig/src/Node/Expression/Binary/NotInBinary.php', 'file' => '../vendor-prefixed/twig/twig/src/Node/Expression/Binary/NotInBinary.php',
'find' => [ 'find' => [
'\'!twig_in_filter(\'' '\'!twig_in_filter(\'',
], ],
'replace' => [ 'replace' => [
'\'!\\\\MailPoetVendor\\\\twig_in_filter(\'', '\'!\\\\MailPoetVendor\\\\twig_in_filter(\'',
@ -53,7 +53,7 @@ $replacements = [
[ [
'file' => '../vendor-prefixed/twig/twig/src/Node/Expression/Binary/InBinary.php', 'file' => '../vendor-prefixed/twig/twig/src/Node/Expression/Binary/InBinary.php',
'find' => [ 'find' => [
'\'twig_in_filter(\'' '\'twig_in_filter(\'',
], ],
'replace' => [ 'replace' => [
'\'\\\\MailPoetVendor\\\\twig_in_filter(\'', '\'\\\\MailPoetVendor\\\\twig_in_filter(\'',

View File

@ -18,7 +18,7 @@ return [
'vendor-bin', 'vendor-bin',
'composer', 'composer',
]) ])
->in('vendor') ->in('vendor'),
], ],
// Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving // Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving

View File

@ -1,4 +1,7 @@
<?php <?php
namespace MailPoet\Sniffs;
/** /**
* Verifies spacing of control statements. * Verifies spacing of control statements.
* *
@ -29,7 +32,7 @@ if (class_exists('PHP_CodeSniffer\Sniffs\AbstractPatternSniff', true) === false)
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer
*/ */
class MailPoet_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer\Sniffs\AbstractPatternSniff { class ControlSignatureSniff extends \PHP_CodeSniffer\Sniffs\AbstractPatternSniff {
/** /**
* If true, comments will be ignored if they are found in the code. * If true, comments will be ignored if they are found in the code.
@ -44,7 +47,7 @@ class MailPoet_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSn
* @return string[] * @return string[]
*/ */
protected function getPatterns() { protected function getPatterns() {
return array( return [
'do {EOL...} while (...);EOL', 'do {EOL...} while (...);EOL',
'while (...) {EOL', 'while (...) {EOL',
'for (...) {EOL', 'for (...) {EOL',
@ -56,6 +59,6 @@ class MailPoet_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSn
'do {EOL', 'do {EOL',
'switch (...) {EOL', 'switch (...) {EOL',
'catch (...) {EOL', 'catch (...) {EOL',
); ];
} }
} }

View File

@ -18,7 +18,7 @@ if (count($argv) !== 2) {
} }
// absolutize path (if not absolute) // absolutize path (if not absolute)
$directory = rtrim($argv[1]. '/'); $directory = rtrim($argv[1] . '/');
if (mb_substr($directory, 0, 1) !== DIRECTORY_SEPARATOR) { if (mb_substr($directory, 0, 1) !== DIRECTORY_SEPARATOR) {
$directory = getcwd() . DIRECTORY_SEPARATOR . $directory; $directory = getcwd() . DIRECTORY_SEPARATOR . $directory;
} }

View File

@ -5,16 +5,14 @@ namespace MailPoet\Premium\DI;
use MailPoet\DI\IContainerConfigurator; use MailPoet\DI\IContainerConfigurator;
use MailPoetVendor\Symfony\Component\DependencyInjection\ContainerBuilder; use MailPoetVendor\Symfony\Component\DependencyInjection\ContainerBuilder;
class ContainerConfigurator implements IContainerConfigurator{ // phpcs:ignore Squiz.Classes.ClassFileName
function configure(ContainerBuilder $container) class ContainerConfigurator implements IContainerConfigurator {
{ function configure(ContainerBuilder $container) {
} }
function getDumpNamespace() function getDumpNamespace() {
{
} }
function getDumpClassname() function getDumpClassname() {
{
} }
} }

View File

@ -5,7 +5,8 @@ define('ABSPATH', getenv('WP_ROOT') . '/');
require_once ABSPATH . 'wp-load.php'; require_once ABSPATH . 'wp-load.php';
require_once ABSPATH . 'wp-admin/includes/admin.php'; require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . '/wp-includes/class-phpmailer.php'; require_once ABSPATH . '/wp-includes/class-phpmailer.php';
if(!class_exists('\MailPoet\Premium\DI\ContainerConfigurator')) {
if (!class_exists('\MailPoet\Premium\DI\ContainerConfigurator')) {
require_once './PremiumContainerConfigurator.php'; require_once './PremiumContainerConfigurator.php';
} }

View File

@ -1,14 +1,17 @@
<?php <?php
class WooCommerce {} // phpcs:ignore
class WooCommerce {
}
/** /**
* @return WooCommerce * @return WooCommerce
*/ */
function WC() {} function WC() {
}
function wc_get_customer_order_count(int $user_id): int { function wc_get_customer_order_count(int $user_id): int {
return 0; return 0;
} }
/** /**
@ -16,7 +19,7 @@ return 0;
* @return mixed * @return mixed
*/ */
function wc_get_order($order = false) { function wc_get_order($order = false) {
return false; return false;
} }
/** /**
@ -24,25 +27,27 @@ return false;
* @return WC_Order[]|int[]|\stdClass * @return WC_Order[]|int[]|\stdClass
*/ */
function wc_get_orders($args) { function wc_get_orders($args) {
return []; return [];
} }
function wc_price(float $price, array $args = []): string { function wc_price(float $price, array $args = []): string {
return ''; return '';
} }
/** /**
* @return string * @return string
*/ */
function get_woocommerce_currency() { function get_woocommerce_currency() {
return ''; return '';
} }
function wc_get_product($the_product = false, $deprecated = array()) { function wc_get_product($the_product = false, $deprecated = []) {
return null; return null;
} }
class WC_DateTime extends \DateTime {} // phpcs:ignore
class WC_DateTime extends \DateTime {
}
/** /**
* @method int get_id() * @method int get_id()
@ -51,4 +56,5 @@ class WC_DateTime extends \DateTime {}
* @method string get_currency(string $context = 'view') * @method string get_currency(string $context = 'view')
* @method float get_total(string $context = 'view') * @method float get_total(string $context = 'view')
*/ */
class WC_Order {} class WC_Order { // phpcs:ignore
}

View File

@ -66,7 +66,7 @@ class GitHubController {
'head' => self::RELEASE_SOURCE_BRANCH, 'head' => self::RELEASE_SOURCE_BRANCH,
'base' => 'master', 'base' => 'master',
'direction' => 'desc', 'direction' => 'desc',
] ],
]); ]);
$response = json_decode($response->getBody()->getContents(), true); $response = json_decode($response->getBody()->getContents(), true);
if (sizeof($response) === 0) { if (sizeof($response) === 0) {
@ -182,11 +182,10 @@ class GitHubController {
return json_decode($response->getBody()->getContents(), true); return json_decode($response->getBody()->getContents(), true);
} }
private function uploadReleaseZip($upload_url, $release_zip_path) private function uploadReleaseZip($upload_url, $release_zip_path) {
{
$this->http_client->post($upload_url, [ $this->http_client->post($upload_url, [
'headers' => [ 'headers' => [
'Content-Type' => 'application/zip' 'Content-Type' => 'application/zip',
], ],
'query' => [ 'query' => [
'name' => $this->zip_filename, 'name' => $this->zip_filename,
@ -195,8 +194,7 @@ class GitHubController {
]); ]);
} }
private function publishDraftAsRelease($release_id) private function publishDraftAsRelease($release_id) {
{
$this->http_client->patch('releases/' . urlencode($release_id), [ $this->http_client->patch('releases/' . urlencode($release_id), [
'json' => [ 'json' => [
'draft' => false, 'draft' => false,

View File

@ -66,7 +66,7 @@ class JiraController {
'query' => [ 'query' => [
'maxResults' => 1, 'maxResults' => 1,
'orderBy' => '-sequence', 'orderBy' => '-sequence',
] ],
]); ]);
$version = json_decode($response->getBody()->getContents(), true); $version = json_decode($response->getBody()->getContents(), true);
if (empty($version) || empty($version['values'])) { if (empty($version) || empty($version['values'])) {
@ -81,7 +81,7 @@ class JiraController {
'maxResults' => 1, 'maxResults' => 1,
'orderBy' => '-sequence', 'orderBy' => '-sequence',
'status' => 'released', 'status' => 'released',
] ],
]); ]);
$version = json_decode($response->getBody()->getContents(), true); $version = json_decode($response->getBody()->getContents(), true);
if (empty($version) || empty($version['values'])) { if (empty($version) || empty($version['values'])) {

View File

@ -97,9 +97,9 @@ class ReleaseVersionController {
$data = [ $data = [
'update' => [ 'update' => [
'fixVersions' => [ 'fixVersions' => [
['set' => [['name' => $version]]] ['set' => [['name' => $version]]],
] ],
] ],
]; ];
return $this->jira->updateIssue($issue_key, $data); return $this->jira->updateIssue($issue_key, $data);
} }

View File

@ -8,7 +8,7 @@ $tools = [
]; ];
// ensure installation in dev-mode only // ensure installation in dev-mode only
$is_dev_mode = (bool) getenv('COMPOSER_DEV_MODE'); $is_dev_mode = (bool)getenv('COMPOSER_DEV_MODE');
if (!$is_dev_mode) { if (!$is_dev_mode) {
fwrite(STDERR, "Skipping installing dev tools in non-dev mode.\n"); fwrite(STDERR, "Skipping installing dev tools in non-dev mode.\n");
return; return;