diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1af966..3f090c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,10 @@ * Case whatever we get from `get_option(uninstall_plugins)` to an array, to avoid throwing a warning. See [#36]. * Fix variable syntax for `.env` file template. See [#38]. * Fix RuntimeException because of `DB_NAME`, `DB_USER`, `DB_PASSWORD` not set. See [#48]. -* Code styles fixes. * Improve `Helpers::addHook()` by using WordPress function when available and loading `plugin.php` earlier on WP 4.7+. See [#50]. +* Add WP CLI step that adds a `wp-cli.yml` file in the project root. See [#33]. +* Code styles fixes. +* Declare strict types in all files. ## [2.3.2] - 2016-07-28 diff --git a/wpstarter/src/Env/Env.php b/wpstarter/src/Env/Env.php index 59a34802..d366310d 100644 --- a/wpstarter/src/Env/Env.php +++ b/wpstarter/src/Env/Env.php @@ -1,9 +1,7 @@ - - * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ diff --git a/wpstarter/src/Env/Loader.php b/wpstarter/src/Env/Loader.php index 6a85cdf2..38ee184a 100644 --- a/wpstarter/src/Env/Loader.php +++ b/wpstarter/src/Env/Loader.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -28,9 +26,9 @@ final class Loader extends DotenvLoader */ public function setEnvironmentVariable($name, $value = null) { - list($name, $value) = $this->normaliseEnvironmentVariable($name, $value); + list($normalised_name, $value) = $this->normaliseEnvironmentVariable($name, $value); - in_array($name, $this->allVars, true) or $this->allVars[] = $name; + in_array($normalised_name, $this->allVars, true) or $this->allVars[] = $normalised_name; if (!$this->immutable || is_null($this->getEnvironmentVariable($name))) { parent::setEnvironmentVariable($name, $value); diff --git a/wpstarter/src/Helpers.php b/wpstarter/src/Helpers.php index 676f5fa9..cd3128cd 100644 --- a/wpstarter/src/Helpers.php +++ b/wpstarter/src/Helpers.php @@ -1,9 +1,7 @@ - - * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -77,7 +75,11 @@ public static function addHook($hook, $callable, $priority = 10, $argsNum = 1) return; } - if (defined(ABSPATH) && is_file(ABSPATH.'wp-includes/plugin.php')) { + if ( + defined(ABSPATH) + && is_file(ABSPATH.'wp-includes/class-wp-hook.php') + && is_file(ABSPATH.'wp-includes/plugin.php') + ) { require_once ABSPATH.'wp-includes/plugin.php'; if (class_exists('WP_Hook')) { add_filter($hook, $callable, $priority, $argsNum); diff --git a/wpstarter/src/MuLoader/MuLoader.php b/wpstarter/src/MuLoader/MuLoader.php index 4d4baf05..74a8a09e 100644 --- a/wpstarter/src/MuLoader/MuLoader.php +++ b/wpstarter/src/MuLoader/MuLoader.php @@ -1,9 +1,7 @@ - - * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -108,7 +106,10 @@ private function loading($refresh, $transient) */ private function loadPlugin($key, $file, $refresh, $transient) { - if (is_readable($file) && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'php') { + if ( + is_readable($file) + && strtolower( (string) pathinfo($file, PATHINFO_EXTENSION)) === 'php' + ) { wp_register_plugin_realpath($file); if (in_array($file, $this->regular, true)) { $this->regularLoaded[] = $file; diff --git a/wpstarter/src/MuLoader/PluginAsMuLoader.php b/wpstarter/src/MuLoader/PluginAsMuLoader.php index 899c5d4f..cf1157da 100644 --- a/wpstarter/src/MuLoader/PluginAsMuLoader.php +++ b/wpstarter/src/MuLoader/PluginAsMuLoader.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup.php b/wpstarter/src/Setup.php index e5990cd0..76fa97f0 100644 --- a/wpstarter/src/Setup.php +++ b/wpstarter/src/Setup.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -25,6 +23,7 @@ use WCM\WPStarter\Setup\Steps\GitignoreStep; use WCM\WPStarter\Setup\Steps\IndexStep; use WCM\WPStarter\Setup\Steps\MoveContentStep; +use WCM\WPStarter\Setup\Steps\WPCliStep; use WCM\WPStarter\Setup\Steps\WPConfigStep; /** @@ -102,6 +101,7 @@ private function install(Composer $composer, Config $config, IO $io, array $extr ->addStep(new EnvExampleStep($io, $builder)) ->addStep(new DropinsStep($io, $overwrite)) ->addStep(new GitignoreStep($io, $builder)) + ->addStep(new WPCliStep($builder)) ->addStep(new MoveContentStep($io)) ->run($paths); } diff --git a/wpstarter/src/Setup/Config.php b/wpstarter/src/Setup/Config.php index bd39ea46..e36606c6 100644 --- a/wpstarter/src/Setup/Config.php +++ b/wpstarter/src/Setup/Config.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -185,7 +183,7 @@ private function validateBoolOrAskOrUrl($value) private function validateBoolOrAsk($value) { $asks = array('ask', 'prompt', 'query', 'interrogate', 'demand'); - if (in_array(trim(strtolower($value)), $asks, true)) { + if (is_string($value) && in_array(trim(strtolower($value)), $asks, true)) { return 'ask'; } diff --git a/wpstarter/src/Setup/FileBuilder.php b/wpstarter/src/Setup/FileBuilder.php index 2b912caa..e7d5ccc1 100644 --- a/wpstarter/src/Setup/FileBuilder.php +++ b/wpstarter/src/Setup/FileBuilder.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/IO.php b/wpstarter/src/Setup/IO.php index 53e62443..14b0567c 100644 --- a/wpstarter/src/Setup/IO.php +++ b/wpstarter/src/Setup/IO.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/OverwriteHelper.php b/wpstarter/src/Setup/OverwriteHelper.php index 78d21269..657c0641 100644 --- a/wpstarter/src/Setup/OverwriteHelper.php +++ b/wpstarter/src/Setup/OverwriteHelper.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Salter.php b/wpstarter/src/Setup/Salter.php index 0764490b..f6edef6d 100644 --- a/wpstarter/src/Setup/Salter.php +++ b/wpstarter/src/Setup/Salter.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Stepper.php b/wpstarter/src/Setup/Stepper.php index 2324f27e..3d5ac245 100644 --- a/wpstarter/src/Setup/Stepper.php +++ b/wpstarter/src/Setup/Stepper.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/StepperInterface.php b/wpstarter/src/Setup/StepperInterface.php index fd0633b8..55593951 100644 --- a/wpstarter/src/Setup/StepperInterface.php +++ b/wpstarter/src/Setup/StepperInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/BlockingStepInterface.php b/wpstarter/src/Setup/Steps/BlockingStepInterface.php index 3a21c779..1de0125c 100644 --- a/wpstarter/src/Setup/Steps/BlockingStepInterface.php +++ b/wpstarter/src/Setup/Steps/BlockingStepInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/CheckPathStep.php b/wpstarter/src/Setup/Steps/CheckPathStep.php index 550fc6c9..1b908cb8 100644 --- a/wpstarter/src/Setup/Steps/CheckPathStep.php +++ b/wpstarter/src/Setup/Steps/CheckPathStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/DropinStep.php b/wpstarter/src/Setup/Steps/DropinStep.php index 3a27c6cf..f23f4c95 100644 --- a/wpstarter/src/Setup/Steps/DropinStep.php +++ b/wpstarter/src/Setup/Steps/DropinStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/DropinsStep.php b/wpstarter/src/Setup/Steps/DropinsStep.php index 5600206a..92395ae8 100644 --- a/wpstarter/src/Setup/Steps/DropinsStep.php +++ b/wpstarter/src/Setup/Steps/DropinsStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -147,7 +145,7 @@ private function validName($name) if ($this->config['unknown-dropins'] === true || in_array($name, self::$dropins, true)) { return true; } - $ext = pathinfo($name, PATHINFO_EXTENSION); + $ext = (string) pathinfo($name, PATHINFO_EXTENSION); if (strtolower($ext) !== 'php') { return $this->config['unknown-dropins'] === 'ask' && $this->ask($name, 0); } diff --git a/wpstarter/src/Setup/Steps/EnvExampleStep.php b/wpstarter/src/Setup/Steps/EnvExampleStep.php index abd15884..a0ce05d1 100644 --- a/wpstarter/src/Setup/Steps/EnvExampleStep.php +++ b/wpstarter/src/Setup/Steps/EnvExampleStep.php @@ -1,13 +1,10 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace WCM\WPStarter\Setup\Steps; use WCM\WPStarter\Setup\IO; diff --git a/wpstarter/src/Setup/Steps/FileStepInterface.php b/wpstarter/src/Setup/Steps/FileStepInterface.php index f4d613a1..ec76db2b 100644 --- a/wpstarter/src/Setup/Steps/FileStepInterface.php +++ b/wpstarter/src/Setup/Steps/FileStepInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/GitignoreStep.php b/wpstarter/src/Setup/Steps/GitignoreStep.php index 8e76ec20..10028ffa 100644 --- a/wpstarter/src/Setup/Steps/GitignoreStep.php +++ b/wpstarter/src/Setup/Steps/GitignoreStep.php @@ -1,13 +1,10 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace WCM\WPStarter\Setup\Steps; use WCM\WPStarter\Setup\Config; diff --git a/wpstarter/src/Setup/Steps/IndexStep.php b/wpstarter/src/Setup/Steps/IndexStep.php index 8854a626..aa357d8a 100644 --- a/wpstarter/src/Setup/Steps/IndexStep.php +++ b/wpstarter/src/Setup/Steps/IndexStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/MoveContentStep.php b/wpstarter/src/Setup/Steps/MoveContentStep.php index f34880bf..dbd2acfb 100644 --- a/wpstarter/src/Setup/Steps/MoveContentStep.php +++ b/wpstarter/src/Setup/Steps/MoveContentStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/OptionalStepInterface.php b/wpstarter/src/Setup/Steps/OptionalStepInterface.php index fd583c79..6237ae35 100644 --- a/wpstarter/src/Setup/Steps/OptionalStepInterface.php +++ b/wpstarter/src/Setup/Steps/OptionalStepInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/PostProcessStepInterface.php b/wpstarter/src/Setup/Steps/PostProcessStepInterface.php index dd898bbe..77d03ea8 100644 --- a/wpstarter/src/Setup/Steps/PostProcessStepInterface.php +++ b/wpstarter/src/Setup/Steps/PostProcessStepInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/StepInterface.php b/wpstarter/src/Setup/Steps/StepInterface.php index c4b5d670..6549a135 100644 --- a/wpstarter/src/Setup/Steps/StepInterface.php +++ b/wpstarter/src/Setup/Steps/StepInterface.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/Steps/WPCliStep.php b/wpstarter/src/Setup/Steps/WPCliStep.php new file mode 100644 index 00000000..605bf509 --- /dev/null +++ b/wpstarter/src/Setup/Steps/WPCliStep.php @@ -0,0 +1,118 @@ + + * @license http://opensource.org/licenses/MIT MIT + * @package WPStarter + */ +class WPCliStep implements FileStepInterface, BlockingStepInterface +{ + /** + * @var \WCM\WPStarter\Setup\FileBuilder + */ + private $builder; + + /** + * @var array + */ + private $vars; + + /** + * @var string + */ + private $error = ''; + + /** + * @param \WCM\WPStarter\Setup\FileBuilder $builder + */ + public function __construct( FileBuilder $builder ) + { + $this->builder = $builder; + } + + /** + * Returns the target path of the file the step will create. + * + * @param \ArrayAccess $paths + * @return string + */ + public function targetPath( ArrayAccess $paths ) + { + return rtrim( $paths['root'], "/" )."/wp-cli.yml"; + } + + /** + * Return true if the step is allowed, i.e. the run method have to be called or not + * + * @param \WCM\WPStarter\Setup\Config $config + * @param \ArrayAccess $paths + * @return bool + */ + public function allowed( Config $config, ArrayAccess $paths ) + { + return true; + } + + /** + * Process the step. + * + * @param \ArrayAccess $paths Have to return one of the step constants. + * @return int + */ + public function run( ArrayAccess $paths ) + { + $wp_install_path = rtrim( "{$paths['root']}/{$paths['wp']}", '/' ); + + $this->vars = array( 'WP_INSTALL_PATH' => $wp_install_path, ); + $build = $this->builder->build( + $paths, + 'wp-cli.yml.example', + $this->vars + ); + + if ( ! $this->builder->save( + $build, + dirname( $this->targetPath( $paths ) ), + 'wp-cli.yml' + ) ) { + $this->error = 'Error while creating wp-cli.yml'; + + return self::ERROR; + } + + return self::SUCCESS; + } + + /** + * Return error message if any. + * + * @return string + */ + public function error() + { + return $this->error; + } + + /** + * Return success message if any. + * + * @return string + */ + public function success() + { + return 'wp-cli.yml saved successfully.'; + } +} \ No newline at end of file diff --git a/wpstarter/src/Setup/Steps/WPConfigStep.php b/wpstarter/src/Setup/Steps/WPConfigStep.php index 8d4df091..f24abbec 100644 --- a/wpstarter/src/Setup/Steps/WPConfigStep.php +++ b/wpstarter/src/Setup/Steps/WPConfigStep.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/src/Setup/UrlDownloader.php b/wpstarter/src/Setup/UrlDownloader.php index 9d66b2da..36760283 100644 --- a/wpstarter/src/Setup/UrlDownloader.php +++ b/wpstarter/src/Setup/UrlDownloader.php @@ -1,8 +1,6 @@ - + * This file is part of the WP Starter package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/wpstarter/templates/wp-cli.yml.example b/wpstarter/templates/wp-cli.yml.example new file mode 100644 index 00000000..df878c32 --- /dev/null +++ b/wpstarter/templates/wp-cli.yml.example @@ -0,0 +1 @@ +path: {{{WP_INSTALL_PATH}}} \ No newline at end of file