From ba9776eb04b4a775eaaa8c7ada75a124e8b9f9c7 Mon Sep 17 00:00:00 2001 From: Agata Date: Mon, 16 Aug 2021 10:47:22 +0200 Subject: [PATCH] add types for php 8 & small code improve --- composer.lock | 295 +++++++++++++++++++++------------ src/Build_Command.php | 4 +- src/Build_Generate_Command.php | 2 +- src/Build_Parser.php | 32 ++-- src/Helper/Utils.php | 51 +++--- src/Helper/WP_API.php | 4 +- src/Processor/Core.php | 37 +++-- src/Processor/Generate.php | 39 +++-- src/Processor/Item.php | 54 +++--- 9 files changed, 315 insertions(+), 203 deletions(-) diff --git a/composer.lock b/composer.lock index 5d7efae..daea4a5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d1acf7d930bb5f2c5a786aacdad9a92", + "content-hash": "0ebf67005b8ae4a03083b3e718790322", "packages": [ { "name": "alchemy/zippy", @@ -12,27 +12,27 @@ "source": { "type": "git", "url": "https://github.com/alchemy-fr/Zippy.git", - "reference": "c79815c422b2754f922810ce029b231dea91ea32" + "reference": "915d604f9e45f757638d06af886cf068acce98c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alchemy-fr/Zippy/zipball/c79815c422b2754f922810ce029b231dea91ea32", - "reference": "c79815c422b2754f922810ce029b231dea91ea32", + "url": "https://api.github.com/repos/alchemy-fr/Zippy/zipball/915d604f9e45f757638d06af886cf068acce98c0", + "reference": "915d604f9e45f757638d06af886cf068acce98c0", "shasum": "" }, "require": { "doctrine/collections": "~1.0", - "php": ">=5.5", - "symfony/filesystem": "^2.0.5 || ^3.0 || ^4.0", + "php": ">=7.1", + "symfony/filesystem": "^2.0.5 || ^3.0 || ^4.0 || ^5.0", "symfony/polyfill-mbstring": "^1.3", - "symfony/process": "^3.4 || ^4.0" + "symfony/process": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { "ext-zip": "*", "guzzle/guzzle": "~3.0", "guzzlehttp/guzzle": "^6.0", - "phpunit/phpunit": "^4.0 || ^5.0", - "symfony/finder": "^2.0.5 || ^3.0 || ^4.0" + "phpunit/phpunit": "^7.0", + "symfony/finder": "^2.0.5 || ^3.0 || ^4.0 || ^5.0" }, "suggest": { "ext-zip": "To use the ZipExtensionAdapter", @@ -71,9 +71,9 @@ ], "support": { "issues": "https://github.com/alchemy-fr/Zippy/issues", - "source": "https://github.com/alchemy-fr/Zippy/tree/master" + "source": "https://github.com/alchemy-fr/Zippy/tree/1.0.0" }, - "time": "2019-04-18T09:48:04+00:00" + "time": "2021-04-13T14:13:44+00:00" }, { "name": "doctrine/collections", @@ -81,19 +81,19 @@ "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "c5f6fffe61e65c82bd005d76350ff52da1f1a3c0" + "reference": "5b8af50f9b830295e45075f878fe8fa1092dcd7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/c5f6fffe61e65c82bd005d76350ff52da1f1a3c0", - "reference": "c5f6fffe61e65c82bd005d76350ff52da1f1a3c0", + "url": "https://api.github.com/repos/doctrine/collections/zipball/5b8af50f9b830295e45075f878fe8fa1092dcd7b", + "reference": "5b8af50f9b830295e45075f878fe8fa1092dcd7b", "shasum": "" }, "require": { "php": "^7.1.3 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0 || ^8.0", + "doctrine/coding-standard": "^9.0", "phpstan/phpstan": "^0.12", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.1.5", "vimeo/psalm": "^4.2.1" @@ -142,20 +142,20 @@ "issues": "https://github.com/doctrine/collections/issues", "source": "https://github.com/doctrine/collections/tree/1.7.x" }, - "time": "2021-01-15T06:54:13+00:00" + "time": "2021-08-11T08:07:00+00:00" }, { "name": "phar-io/version", - "version": "3.0.4", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "e4782611070e50613683d2b9a57730e9a3ba5451" + "reference": "bae7c545bef187884426f042434e561ab1ddb182" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/e4782611070e50613683d2b9a57730e9a3ba5451", - "reference": "e4782611070e50613683d2b9a57730e9a3ba5451", + "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", + "reference": "bae7c545bef187884426f042434e561ab1ddb182", "shasum": "" }, "require": { @@ -191,27 +191,29 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.0.4" + "source": "https://github.com/phar-io/version/tree/3.1.0" }, - "time": "2020-12-13T23:18:30+00:00" + "time": "2021-02-23T14:00:09+00:00" }, { "name": "symfony/filesystem", - "version": "4.4.x-dev", + "version": "5.4.x-dev", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "a27af3baa56c66d37d066e27d4b11ae6b3d51c3b" + "reference": "d5ca5f7080a759dcb65300a55d5ee42f1ee7ef59" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/a27af3baa56c66d37d066e27d4b11ae6b3d51c3b", - "reference": "a27af3baa56c66d37d066e27d4b11ae6b3d51c3b", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/d5ca5f7080a759dcb65300a55d5ee42f1ee7ef59", + "reference": "d5ca5f7080a759dcb65300a55d5ee42f1ee7ef59", "shasum": "" }, "require": { - "php": ">=7.1.3", - "symfony/polyfill-ctype": "~1.8" + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8", + "symfony/polyfill-php80": "^1.16" }, "type": "library", "autoload": { @@ -239,7 +241,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/4.4" + "source": "https://github.com/symfony/filesystem/tree/5.4" }, "funding": [ { @@ -255,7 +257,7 @@ "type": "tidelift" } ], - "time": "2021-01-11T08:57:50+00:00" + "time": "2021-08-13T13:17:20+00:00" }, { "name": "symfony/polyfill-ctype", @@ -263,12 +265,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", "shasum": "" }, "require": { @@ -281,7 +283,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -319,7 +321,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" }, "funding": [ { @@ -335,7 +337,7 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2021-02-19T12:13:01+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -343,12 +345,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13" + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f377a3dd1fde44d37b9831d68dc8dea3ffd28e13", - "reference": "f377a3dd1fde44d37b9831d68dc8dea3ffd28e13", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", "shasum": "" }, "require": { @@ -361,7 +363,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -400,7 +402,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" }, "funding": [ { @@ -416,32 +418,45 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2021-05-27T12:26:48+00:00" }, { - "name": "symfony/process", - "version": "4.4.x-dev", + "name": "symfony/polyfill-php80", + "version": "dev-main", "source": { "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "e9c4ef4f848b04efc5bcd070f8bcede59d637d5c" + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e9c4ef4f848b04efc5bcd070f8bcede59d637d5c", - "reference": "e9c4ef4f848b04efc5bcd070f8bcede59d637d5c", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", "shasum": "" }, "require": { - "php": ">=7.1.3" + "php": ">=7.1" }, + "default-branch": true, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, "autoload": { "psr-4": { - "Symfony\\Component\\Process\\": "" + "Symfony\\Polyfill\\Php80\\": "" }, - "exclude-from-classmap": [ - "/Tests/" + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" ] }, "notification-url": "https://packagist.org/downloads/", @@ -450,18 +465,81 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.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-07-28T13:41:28+00:00" + }, + { + "name": "symfony/process", + "version": "5.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "38f26c7d6ed535217ea393e05634cb0b244a1967" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/38f26c7d6ed535217ea393e05634cb0b244a1967", + "reference": "38f26c7d6ed535217ea393e05634cb0b244a1967", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-php80": "^1.16" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/4.4" + "source": "https://github.com/symfony/process/tree/5.3" }, "funding": [ { @@ -477,7 +555,7 @@ "type": "tidelift" } ], - "time": "2021-01-14T15:08:15+00:00" + "time": "2021-08-04T21:20:46+00:00" }, { "name": "symfony/yaml", @@ -515,22 +593,13 @@ "psr-4": { "Symfony\\Component\\Yaml\\": "" }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "url": "https://github.com/fabpot", + "type": "github" }, { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" } ], "description": "Symfony Yaml Component", @@ -559,6 +628,9 @@ "require": { "php": ">=5.2.4" }, + "conflict": { + "symfony/console": "<3.4" + }, "require-dev": { "friendsofphp/php-cs-fixer": "~1.11", "phpunit/phpunit": "~3.7|~4.0|~5.0" @@ -594,23 +666,30 @@ }, { "name": "rmccue/requests", - "version": "v1.7.0", + "version": "v1.8.1", "source": { "type": "git", - "url": "https://github.com/rmccue/Requests.git", - "reference": "87932f52ffad70504d93f04f15690cf16a089546" + "url": "https://github.com/WordPress/Requests.git", + "reference": "82e6936366eac3af4d836c18b9d8c31028fe4cd5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rmccue/Requests/zipball/87932f52ffad70504d93f04f15690cf16a089546", - "reference": "87932f52ffad70504d93f04f15690cf16a089546", + "url": "https://api.github.com/repos/WordPress/Requests/zipball/82e6936366eac3af4d836c18b9d8c31028fe4cd5", + "reference": "82e6936366eac3af4d836c18b9d8c31028fe4cd5", "shasum": "" }, "require": { "php": ">=5.2" }, "require-dev": { - "requests/test-server": "dev-master" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "php-parallel-lint/php-console-highlighter": "^0.5.0", + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpcompatibility/php-compatibility": "^9.0", + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5", + "requests/test-server": "dev-master", + "squizlabs/php_codesniffer": "^3.5", + "wp-coding-standards/wpcs": "^2.0" }, "type": "library", "autoload": { @@ -629,7 +708,7 @@ } ], "description": "A HTTP library written in PHP, for human beings.", - "homepage": "http://github.com/rmccue/Requests", + "homepage": "http://github.com/WordPress/Requests", "keywords": [ "curl", "fsockopen", @@ -640,27 +719,28 @@ "sockets" ], "support": { - "issues": "https://github.com/rmccue/Requests/issues", - "source": "https://github.com/rmccue/Requests/tree/master" + "issues": "https://github.com/WordPress/Requests/issues", + "source": "https://github.com/WordPress/Requests/tree/v1.8.1" }, - "time": "2016-10-13T00:11:37+00:00" + "time": "2021-06-04T09:56:25+00:00" }, { "name": "symfony/finder", - "version": "5.x-dev", + "version": "5.3.x-dev", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "03ff88196e9fec7f273469020b3939b1330e2156" + "reference": "a10000ada1e600d109a6c7632e9ac42e8bf2fb93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/03ff88196e9fec7f273469020b3939b1330e2156", - "reference": "03ff88196e9fec7f273469020b3939b1330e2156", + "url": "https://api.github.com/repos/symfony/finder/zipball/a10000ada1e600d109a6c7632e9ac42e8bf2fb93", + "reference": "a10000ada1e600d109a6c7632e9ac42e8bf2fb93", "shasum": "" }, "require": { - "php": ">=7.2.5" + "php": ">=7.2.5", + "symfony/polyfill-php80": "^1.16" }, "default-branch": true, "type": "library", @@ -678,18 +758,15 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Justin Hileman", + "email": "justin@justinhileman.info", + "homepage": "http://justinhileman.com" } ], "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/5.x" + "source": "https://github.com/symfony/finder/tree/5.3" }, "funding": [ { @@ -705,7 +782,7 @@ "type": "tidelift" } ], - "time": "2021-01-11T09:50:50+00:00" + "time": "2021-08-04T21:20:46+00:00" }, { "name": "wp-cli/mustangostang-spyc", @@ -760,16 +837,16 @@ }, { "name": "wp-cli/php-cli-tools", - "version": "v0.11.11", + "version": "v0.11.13", "source": { "type": "git", "url": "https://github.com/wp-cli/php-cli-tools.git", - "reference": "fe9c7c44a9e1bf2196ec51dc38da0593dbf2993f" + "reference": "a2866855ac1abc53005c102e901553ad5772dc04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/fe9c7c44a9e1bf2196ec51dc38da0593dbf2993f", - "reference": "fe9c7c44a9e1bf2196ec51dc38da0593dbf2993f", + "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/a2866855ac1abc53005c102e901553ad5772dc04", + "reference": "a2866855ac1abc53005c102e901553ad5772dc04", "shasum": "" }, "require": { @@ -789,15 +866,15 @@ "MIT" ], "authors": [ - { - "name": "James Logsdon", - "email": "jlogsdon@php.net", - "role": "Developer" - }, { "name": "Daniel Bachhuber", "email": "daniel@handbuilt.co", "role": "Maintainer" + }, + { + "name": "James Logsdon", + "email": "jlogsdon@php.net", + "role": "Developer" } ], "description": "Console utilities for PHP", @@ -808,9 +885,9 @@ ], "support": { "issues": "https://github.com/wp-cli/php-cli-tools/issues", - "source": "https://github.com/wp-cli/php-cli-tools/tree/master" + "source": "https://github.com/wp-cli/php-cli-tools/tree/v0.11.13" }, - "time": "2018-09-04T13:28:00+00:00" + "time": "2021-07-01T15:08:16+00:00" }, { "name": "wp-cli/wp-cli", @@ -818,19 +895,19 @@ "source": { "type": "git", "url": "https://github.com/wp-cli/wp-cli.git", - "reference": "760cc6effd86cc4a4f96e0bfaee6f7f01b62c42b" + "reference": "c4aba2085554e8872c0fb78ba25e7cf8d337e24a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/760cc6effd86cc4a4f96e0bfaee6f7f01b62c42b", - "reference": "760cc6effd86cc4a4f96e0bfaee6f7f01b62c42b", + "url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/c4aba2085554e8872c0fb78ba25e7cf8d337e24a", + "reference": "c4aba2085554e8872c0fb78ba25e7cf8d337e24a", "shasum": "" }, "require": { "ext-curl": "*", "mustache/mustache": "~2.13", "php": "^5.6 || ^7.0 || ^8.0", - "rmccue/requests": "~1.6", + "rmccue/requests": "^1.8", "symfony/finder": ">2.7", "wp-cli/mustangostang-spyc": "^0.6.3", "wp-cli/php-cli-tools": "~0.11.2" @@ -841,7 +918,7 @@ "wp-cli/entity-command": "^1.2 || ^2", "wp-cli/extension-command": "^1.1 || ^2", "wp-cli/package-command": "^1 || ^2", - "wp-cli/wp-cli-tests": "^2.1.14" + "wp-cli/wp-cli-tests": "^3.0.7" }, "suggest": { "ext-readline": "Include for a better --prompt implementation", @@ -882,7 +959,7 @@ "issues": "https://github.com/wp-cli/wp-cli/issues", "source": "https://github.com/wp-cli/wp-cli" }, - "time": "2020-12-08T18:52:39+00:00" + "time": "2021-08-12T15:46:55+00:00" } ], "aliases": [], diff --git a/src/Build_Command.php b/src/Build_Command.php index 2ce1e3a..2f25d84 100644 --- a/src/Build_Command.php +++ b/src/Build_Command.php @@ -8,7 +8,7 @@ class Build_Command extends \WP_CLI_Command { /** - * Installs wordpress, plugins and themes. + * Installs WordPress, plugins and themes. * * ## OPTIONS * @@ -67,7 +67,7 @@ class Build_Command extends \WP_CLI_Command { * * @when before_wp_load */ - public function __invoke( $args = NULL, $assoc_args = NULL ) { + public function __invoke( $args = null, $assoc_args = null ) { $build_filename = Utils::get_build_filename( $assoc_args ); WP_CLI::line( WP_CLI::colorize( "%GParsing %W$build_filename%n%G, please wait...%n" ) ); diff --git a/src/Build_Generate_Command.php b/src/Build_Generate_Command.php index 05f869c..6afadc9 100644 --- a/src/Build_Generate_Command.php +++ b/src/Build_Generate_Command.php @@ -33,7 +33,7 @@ class Build_Generate_Command extends \WP_CLI_Command { * wp build-generate --output=production.yml * */ - public function __invoke( $args = NULL, $assoc_args = NULL ) { + public function __invoke( $args = null, $assoc_args = null ) { // Build file. $build_filename = Utils::get_build_filename( $assoc_args ); diff --git a/src/Build_Parser.php b/src/Build_Parser.php index 62856e6..234fa46 100644 --- a/src/Build_Parser.php +++ b/src/Build_Parser.php @@ -6,20 +6,21 @@ class Build_Parser { - private $filename = 'build.json'; - private $format = 'json'; - private $build = []; + private mixed $filename = 'build.json'; + private string $format = 'json'; + private array $build = []; - public function __construct( $filename, $assoc_args = NULL ) { + public function __construct( $filename, $assoc_args = null ) { // Set Build file. $this->filename = empty( $filename ) ? 'build.json' : $filename; // Set format. - $this->format = ( strpos( $this->filename, 'yml' ) !== FALSE ) ? 'yml' : 'json'; + $this->format = (str_contains($this->filename, 'yml')) ? 'yml' : 'json'; // Parse the Build file and Build sure it's valid. $this->parse(); } - private function parse() { + private function parse(): void + { // Full Build file path. $file_path = ( Utils::is_absolute_path( $this->filename ) ) ? $this->filename : realpath( '.' ) . '/' . $this->filename; // Set specified path with --path argument. @@ -28,7 +29,7 @@ private function parse() { } // Check if the file exists. if ( ! file_exists( $file_path ) ) { - return NULL; + return; } // Check if the Build file is a valid yaml file. if ( $this->format == 'yml' ) { @@ -37,10 +38,10 @@ private function parse() { } catch ( \Exception $e ) { WP_CLI::error( 'Error parsing YAML from Build file (' . $this->filename . ').' ); - return FALSE; + return; } - return TRUE; + return; } // Build.json @@ -49,13 +50,12 @@ private function parse() { } catch ( \Exception $e ) { WP_CLI::error( 'Error parsing JSON from Build file (' . $this->filename . ').' ); - return FALSE; + return; } - return TRUE; - } + } - public function get( $key = NULL, $sub_key = NULL ) { + public function get( $key = null, $sub_key = null ) { // With subkey. if ( ! empty( $this->build[ $key ][ $sub_key ] ) ) { @@ -75,7 +75,7 @@ public function get_core_version() { return $this->build['core']['download']['version']; } - return NULL; + return null; } public function get_plugin_version( $slug ) { @@ -83,7 +83,7 @@ public function get_plugin_version( $slug ) { return $this->build['plugins'][ $slug ]['version']; } - return NULL; + return null; } public function get_theme_version( $slug ) { @@ -91,6 +91,6 @@ public function get_theme_version( $slug ) { return $this->build['themes'][ $slug ]['version']; } - return NULL; + return null; } } \ No newline at end of file diff --git a/src/Helper/Utils.php b/src/Helper/Utils.php index dd7b1c8..1da3f90 100644 --- a/src/Helper/Utils.php +++ b/src/Helper/Utils.php @@ -12,7 +12,8 @@ class Utils { - public static function wp_config_exists() { + public static function wp_config_exists(): bool + { if ( ( file_exists( realpath( '.' ) . '/wp-config.php' ) ) || ( file_exists( ABSPATH . '/wp-config.php' ) ) ) { return TRUE; } @@ -21,7 +22,8 @@ public static function wp_config_exists() { } // Return WP version. - public static function wp_version() { + public static function wp_version(): bool|string + { $result = self::launch_self( 'core', [ 'version' ], [], FALSE, TRUE, [], FALSE, FALSE ); if ( ! empty( $result->stdout ) ) { return trim( $result->stdout ); @@ -31,7 +33,8 @@ public static function wp_version() { } // Check if WP is installed. - public static function wp_installed() { + public static function wp_installed(): bool + { $result = self::launch_self( 'core', [ 'is-installed' ], [], FALSE, TRUE, [], FALSE, FALSE ); if ( ! empty( $result->return_code ) ) { return FALSE; @@ -40,7 +43,8 @@ public static function wp_installed() { return TRUE; } - public static function wp_path( $path = NULL ) { + public static function wp_path( $path = null ): string + { $wp_path = ABSPATH; if ( ! empty( $path ) ) { $wp_path = ( ( ! self::is_absolute_path( ABSPATH ) ) || ( $wp_path == '/' ) ) ? getcwd() . '/' . $path : $wp_path . '/' . $path; @@ -50,11 +54,12 @@ public static function wp_path( $path = NULL ) { } public static function line( $text, $pseudo_tab = FALSE ) { - $spaces = ( $pseudo_tab ) ? ' ' : NULL; + $spaces = ( $pseudo_tab ) ? ' ' : null; echo $spaces . WP_CLI::colorize( $text ); } - public static function prompt( $question ) { + public static function prompt( $question ): bool|string + { if ( function_exists( 'readline' ) ) { return readline( $question ); } else { @@ -64,7 +69,8 @@ public static function prompt( $question ) { } } - public static function is_absolute_path( $path ) { + public static function is_absolute_path( $path ): bool + { if ( ! is_string( $path ) ) { $mess = sprintf( 'String expected but was given %s', gettype( $path ) ); throw new \InvalidArgumentException( $mess ); @@ -113,7 +119,8 @@ public static function launch_self( $command, $args = [], $assoc_args = [], $exi return $result; } - private static function get_launch_self_workaround_command( $command = NULL, $args = [], $assoc_args = [], $runtime_args = [] ) { + private static function get_launch_self_workaround_command( $command = null, $args = [], $assoc_args = [], $runtime_args = [] ): string + { $reused_runtime_args = [ 'path', 'url', @@ -142,7 +149,8 @@ private static function get_launch_self_workaround_command( $command = NULL, $ar return "WP_CLI_CACHE_DIR={$cache_dir} WP_CLI_CONFIG_PATH={$config_path} {$php_bin} {$script_path} {$command} {$args} {$assoc_args}"; } - public static function item_download( $type = NULL, $slug = NULL, $version = NULL ) { + public static function item_download( $type = null, $slug = null, $version = null ): bool|string|null + { if ( ( ! empty( $slug ) ) && ( $type == 'plugin' || $type == 'theme' ) && ( ! empty( $version ) ) ) { $info_fn = $type . '_info'; $info = WP_API::$info_fn( $slug, $version ); @@ -151,9 +159,9 @@ public static function item_download( $type = NULL, $slug = NULL, $version = NUL } // Status message. $status = ''; - // Uses custom 'version_link' to download the item. - if ( ! empty( $info->version_link ) ) { - $failed_version_download = FALSE; + $failed_version_download = FALSE; + // Uses custom 'version_link' to download the item. + if ( ! empty( $info->version_link ) ) { $filename = basename( $info->version_link ); if ( ! empty( $filename ) ) { $download = Utils::download_url( $info->version_link ); @@ -199,7 +207,8 @@ public static function item_download( $type = NULL, $slug = NULL, $version = NUL return NULL; } - public static function download_url( $url = NULL ) { + public static function download_url( $url = null ): bool|int|string + { // If we have an URL proceed. if ( ! empty( $url ) ) { $filename = basename( $url ); @@ -228,7 +237,8 @@ public static function download_url( $url = NULL ) { return FALSE; } - public static function item_unzip( $type, $filename ) { + public static function item_unzip( $type, $filename ): bool + { $file_path = self::wp_path( 'wp-content/' . $filename ); if ( file_exists( $file_path ) ) { if ( self::unzip( $file_path, Utils::wp_path( 'wp-content/' . $type . 's/' ) ) ) { @@ -239,7 +249,8 @@ public static function item_unzip( $type, $filename ) { return FALSE; } - public static function unzip( $file, $to, $delete = TRUE ) { + public static function unzip( $file, $to, $delete = TRUE ): bool + { if ( ( ! empty( $file ) ) && ( ! empty( $to ) ) ) { // Create the directory to extract to. @@ -271,7 +282,8 @@ public static function unzip( $file, $to, $delete = TRUE ) { return FALSE; } - public static function mkdir( $dir = NULL ) { + public static function mkdir( $dir = null ): bool|string + { if ( ! empty( $dir ) ) { if ( ! file_exists( $dir ) ) { $fs = new Filesystem(); @@ -293,7 +305,8 @@ public static function mkdir( $dir = NULL ) { } // Print success or error message. - public static function result( $result = NULL ) { + public static function result( $result = null ): bool + { if ( ! empty( $result ) ) { // Success. if ( ! empty( $result->stdout ) && ( empty( $result->stderr ) ) ) { @@ -314,7 +327,7 @@ public static function result( $result = NULL ) { public static function convert_to_numeric( $version = NULL ) { if ( ( ! empty( $version ) ) && ( is_numeric( $version ) ) ) { - return strpos( $version, '.' ) === FALSE ? (int) $version : (float) $version; + return !str_contains($version, '.') ? (int) $version : (float) $version; } return $version; @@ -408,4 +421,4 @@ public static function determine_version( $item_version, $wporg_latest, $wporg_v return $item_version; } -} \ No newline at end of file +} diff --git a/src/Helper/WP_API.php b/src/Helper/WP_API.php index 395e1d5..c005f52 100644 --- a/src/Helper/WP_API.php +++ b/src/Helper/WP_API.php @@ -4,7 +4,7 @@ class WP_API { - public static function core_version_check( $config_version = NULL ) { + public static function core_version_check( $config_version = null ) { $response = Requests::get( 'http://api.wordpress.org/core/version-check/1.7/' ); if ( ! empty( $response->body ) ) { $core = json_decode( $response->body ); @@ -94,4 +94,4 @@ private static function _get_item_download_link( $item, $version ) { } -} \ No newline at end of file +} diff --git a/src/Processor/Core.php b/src/Processor/Core.php index e113f00..733245a 100644 --- a/src/Processor/Core.php +++ b/src/Processor/Core.php @@ -7,17 +7,18 @@ class Core { - private $build; - private $assoc_args; + private Build_Parser $build; + private mixed $assoc_args; - public function __construct( $assoc_args = NULL ) { + public function __construct( $assoc_args = null ) { // Build file. $this->build = new Build_Parser( Utils::get_build_filename( $assoc_args ), $assoc_args ); // Set command arguments. $this->assoc_args = $assoc_args; } - public function process() { + public function process(): bool + { // WP installation status. $installed = Utils::wp_installed(); // Check if we have core info in build.yml. @@ -45,11 +46,12 @@ public function process() { } // Update WordPress if build.yml version is higher than currently installed. - private function update_wordpress() { + private function update_wordpress(): ?bool + { // Config $config = $this->build->get( 'core', 'download' ); $installed_version = Utils::wp_version(); - $config_version = empty( $config['version'] ) ? NULL : $config['version']; + $config_version = empty( $config['version'] ) ? null : $config['version']; $version_to_install = WP_API::core_version_check( $config_version ); // Compare installed version with the one in build.yml. if ( version_compare( $installed_version, $version_to_install ) === - 1 ) { @@ -64,11 +66,12 @@ private function update_wordpress() { return Utils::result( $result ); } - return NULL; + return null; } // Download WordPress if not downloaded or if force setting is defined. - private function download_wordpress() { + private function download_wordpress(): ?bool + { // Version check. $version_check = Utils::wp_version(); // Config @@ -85,7 +88,7 @@ private function download_wordpress() { // Download WP without the default themes and plugins $download_args['skip-content'] = isset( $config['skip-content'] ) ? $config['skip-content'] : TRUE; // Whether to exit on error or not - $exit_on_error = isset( $config['exit-on-error'] ) ? $config['exit-on-error'] : FALSE; + $exit_on_error = $config['exit-on-error'] ?? FALSE; // Force download. if ( ( ! empty( $config['force'] ) ) && ( $config['force'] === TRUE ) ) { $download_args['force'] = TRUE; @@ -101,11 +104,12 @@ private function download_wordpress() { } } - return NULL; + return null; } // Configure WordPress if 'wp-config.php' is not found. - private function config_wordpress() { + private function config_wordpress(): ?bool + { // Check if wp-config.php exists. if ( ( ! Utils::wp_config_exists() ) || ( ! empty( $this->assoc_args['force'] ) ) ) { // Version check. @@ -166,10 +170,11 @@ private function config_wordpress() { } } - return NULL; + return null; } - private function install_wordpress() { + private function install_wordpress(): ?bool + { // Check if wp-config.php exists. if ( Utils::wp_config_exists() ) { // Config @@ -199,10 +204,10 @@ private function install_wordpress() { // Check if admin password is set, if not, ask for it. if ( empty( $config['admin-pass'] ) ) { - $config['admin-pass'] = NULL; + $config['admin-pass'] = null; do { $config['admin-pass'] = Utils::prompt( WP_CLI::colorize( " Enter the admin %Rpassword%n for the user %G{$config['admin-user']}%n: " ) ); - } while ( $config['admin-pass'] == NULL ); + } while ( $config['admin-pass'] == null ); } $install_args['admin_password'] = $config['admin-pass']; @@ -215,7 +220,7 @@ private function install_wordpress() { } } - return NULL; + return null; } } diff --git a/src/Processor/Generate.php b/src/Processor/Generate.php index b16f817..40fdf72 100644 --- a/src/Processor/Generate.php +++ b/src/Processor/Generate.php @@ -7,14 +7,14 @@ class Generate { - private $core; - private $plugins; - private $themes; - private $assoc_args; - private $build_file; - private $build_filename; - - public function __construct( $assoc_args = NULL, $build_filename = NULL ) { + private array $core; + private array $plugins; + private array $themes; + private mixed $assoc_args; + private Build_Parser $build_file; + private mixed $build_filename; + + public function __construct( $assoc_args = null, $build_filename = null ) { // Cmd line arguments. $this->assoc_args = $assoc_args; // Existing build file (if any). @@ -52,7 +52,7 @@ public function create_build_file() { Utils::line( "%WGenerating %n%Y$this->build_filename%n%W with the items from %Ywp.org%n%W, please wait...%n" ); // YAML. - if ( ( ( ! empty( $this->assoc_args['format'] ) ) && ( $this->assoc_args['format'] == 'yml' ) ) || ( strpos( $this->build_filename, 'yml' ) !== FALSE ) ) { + if ( ( ( ! empty( $this->assoc_args['format'] ) ) && ( $this->assoc_args['format'] == 'yml' ) ) || (str_contains($this->build_filename, 'yml')) ) { $content = Yaml::dump( $build, 10 ); } @@ -74,7 +74,8 @@ public function create_build_file() { } - public function create_gitignore() { + public function create_gitignore(): bool + { $custom_items = []; if ( ! empty( $this->plugins['custom'] ) ) { $custom_items['plugins'] = $this->plugins['custom']; @@ -102,7 +103,8 @@ public function create_gitignore() { return FALSE; } - private function get_core() { + private function get_core(): array + { // Verbose output Utils::line( "%W- Checking %n%Ccore%n%W...\n" ); // Get locale @@ -120,11 +122,12 @@ private function get_core() { ); } - private function get_plugins() { + private function get_plugins(): array + { // Verbose output Utils::line( "%W- Checking %n%Cplugins%n%W...\n" ); $installed_plugins = get_plugins(); - $plugins = NULL; + $plugins = null; if ( ! empty( $installed_plugins ) ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; foreach ( $installed_plugins as $file => $details ) { @@ -157,11 +160,12 @@ private function get_plugins() { return $plugins; } - private function get_themes() { + private function get_themes(): array + { // Verbose output Utils::line( "%W- Checking %n%Cthemes%n%W...\n" ); $installed_themes = wp_get_themes(); - $themes = NULL; + $themes = null; if ( ! empty( $installed_themes ) ) { $current_theme = get_stylesheet(); foreach ( $installed_themes as $slug => $theme ) { @@ -194,7 +198,7 @@ private function get_themes() { // Message. Utils::line( "%W %n%G$main_theme%n%W (%n$origin_colorize%W)\n" ); // Add theme to the themes list. - $themes[ $origin ][ $main_theme ] = NULL; + $themes[ $origin ][ $main_theme ] = null; } } } @@ -204,7 +208,8 @@ private function get_themes() { return $themes; } - private function save_gitignore( $custom_items = [] ) { + private function save_gitignore( $custom_items = [] ): bool + { // .gitignore path. $gitignore_path = ABSPATH . '.gitignore'; if ( $gitignore_path == '/.gitignore' ) { diff --git a/src/Processor/Item.php b/src/Processor/Item.php index 0aefbf8..3d22b81 100644 --- a/src/Processor/Item.php +++ b/src/Processor/Item.php @@ -7,17 +7,18 @@ class Item { - private $build; + private Build_Parser $build; - public function __construct( $assoc_args = NULL ) { + public function __construct( $assoc_args = null ) { // Build file. $this->build = new Build_Parser( Utils::get_build_filename( $assoc_args ) ); $this->filesystem = new Filesystem(); - $this->clean = empty( $assoc_args['clean'] ) ? FALSE : TRUE; + $this->clean = !empty($assoc_args['clean']); } // Starts processing items. - public function run( $item_type = NULL ) { + public function run( $item_type = null ): bool + { $result = FALSE; if ( ( $item_type == 'plugin' ) || ( $item_type == 'theme' ) ) { if ( ! empty( $this->build ) ) { @@ -33,7 +34,8 @@ public function run( $item_type = NULL ) { } // Process item (plugin or theme). - private function process( $type = NULL, $items = [], $defaults = [] ) { + private function process( $type = null, $items = [], $defaults = [] ): bool + { $result = FALSE; if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $items ) ) ) { // Check if WP is installed. @@ -81,7 +83,8 @@ private function process( $type = NULL, $items = [], $defaults = [] ) { } // Download an item. - private function download( $type = NULL, $item = NULL, $item_info = NULL ) { + private function download( $type = null, $item = null, $item_info = null ): bool + { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $item ) ) && ( ! empty( $item_info ) ) ) { // Check if the item folder already exists or not. // If the folder exists and the version is the same as the build file, skip it. @@ -100,10 +103,13 @@ private function download( $type = NULL, $item = NULL, $item_info = NULL ) { return TRUE; } } + + return FALSE; } // Install and activate an item. - private function install( $type = NULL, $item = NULL, $item_info = NULL, $defaults = [] ) { + private function install( $type = null, $item = null, $item_info = null, $defaults = [] ): bool + { // Processing text. $process = "- Installing %G$item%n"; @@ -117,7 +123,7 @@ private function install( $type = NULL, $item = NULL, $item_info = NULL, $defaul $defaults_code = [ 'version' => 'latest', 'force' => FALSE, 'activate' => FALSE, 'activate-network' => FALSE, 'gitignore' => FALSE ]; $defaults = array_merge( $defaults_code, $defaults ); - // Merge item info with the defaults (ixtem info will override defaults). + // Merge item info with the defaults (item info will override defaults). $item_info = array_merge( $defaults, $item_info ); // Item version. @@ -126,7 +132,7 @@ private function install( $type = NULL, $item = NULL, $item_info = NULL, $defaul $install_args['version'] = $item_info['version']; } - // Wether to force installation if the item is already installed. + // Whether to force installation if the item is already installed. if ( ( ! empty( $item_info['force'] ) ) && ( $item_info['force'] ) ) { $install_args['force'] = TRUE; } @@ -152,7 +158,8 @@ private function install( $type = NULL, $item = NULL, $item_info = NULL, $defaul } // Activate an item. - private function activate( $type = NULL, $item = NULL, $item_info = NULL ) { + private function activate( $type = null, $item = null, $item_info = null ): bool + { // Processing text. $process = "- Activating %G$item%n (%Y{$item_info['version']}%n)"; @@ -167,7 +174,8 @@ private function activate( $type = NULL, $item = NULL, $item_info = NULL ) { } // Activate an item. - private function update( $type = NULL, $item = NULL, $item_info = NULL ) { + private function update( $type = null, $item = null, $item_info = null ): bool + { // Current version. $old_version = $this->version( $type, $item ); @@ -188,7 +196,8 @@ private function update( $type = NULL, $item = NULL, $item_info = NULL ) { return Utils::result( $result ); } - private function version( $type = NULL, $name = NULL ) { + private function version( $type = null, $name = null ): bool|string + { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $name ) ) ) { $result = Utils::launch_self( $type, [ 'get', $name ], [ 'field' => 'version' ], FALSE, TRUE, [], FALSE, FALSE ); if ( ! empty( $result->stdout ) ) { @@ -199,7 +208,8 @@ private function version( $type = NULL, $name = NULL ) { return FALSE; } - private function status( $type = NULL, $name = NULL ) { + private function status( $type = null, $name = null ): bool|string + { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $name ) ) ) { $result = Utils::launch_self( $type, [ 'status', $name ], [], FALSE, TRUE, [], FALSE, FALSE ); $result = trim( strtolower( $result->stdout ) ); @@ -214,7 +224,8 @@ private function status( $type = NULL, $name = NULL ) { return FALSE; } - private function is_active( $type = NULL, $name = NULL ) { + private function is_active( $type = null, $name = null ): bool + { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $name ) ) ) { $result = Utils::launch_self( $type, [ 'is-active', $name ], [], FALSE, TRUE, [], FALSE, FALSE ); if ( empty( $result->return_code ) ) { @@ -225,7 +236,7 @@ private function is_active( $type = NULL, $name = NULL ) { return FALSE; } - private function get_item_info( $type = NULL, $slug = NULL, $version = '*', $field = NULL ) { + private function get_item_info( $type = null, $slug = null, $version = '*', $field = null ) { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $slug ) ) ) { $info_fn = $type . '_info'; $info = WP_API::$info_fn( $slug, $version, FALSE ); @@ -236,10 +247,10 @@ private function get_item_info( $type = NULL, $slug = NULL, $version = '*', $fie return $info; } - return NULL; + return null; } - private function set_item_version( $type = NULL, $slug = NULL, $item_version = '*' ) { + private function set_item_version( $type = null, $slug = null, $item_version = '*' ) { if ( ( $type == 'theme' || $type == 'plugin' ) && ( ! empty( $slug ) ) ) { $item_info = $this->get_item_info( $type, $slug, $item_version ); if ( ! empty( $item_info->version ) ) { @@ -250,14 +261,15 @@ private function set_item_version( $type = NULL, $slug = NULL, $item_version = ' return ( $item_version === '*' ) ? 'latest' : $item_version; } - private function delete_item_folder( $type = NULL, $item = NULL ) { + private function delete_item_folder( $type = null, $item = null ): void + { if ( ( ! empty( $type ) ) && ( ! empty( $item ) ) ) { $folder = Utils::wp_path( 'wp-content/' . $type . 's/' . $item ); - return $this->filesystem->remove( $folder ); + $this->filesystem->remove($folder); + return; } - return FALSE; - } + } } \ No newline at end of file