From c36b65b8e08e882416660fc0c812dd430dfcf708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCnter?= Date: Tue, 7 Apr 2020 20:07:27 +0200 Subject: [PATCH] style: reformat php codebase (#4gg05b) --- package.json | 3 +- packages/utils/src/Assets.php | 12 +++- packages/utils/test/phpunit/AssetsTest.php | 71 +++++++++++++++---- plugins/wp-reactjs-starter/src/inc/Assets.php | 9 +-- .../wp-reactjs-starter/src/inc/base/index.php | 1 - .../src/inc/base/others/index.php | 1 - .../src/inc/base/others/start.php | 2 +- plugins/wp-reactjs-starter/src/inc/index.php | 1 - .../wp-reactjs-starter/src/inc/rest/index.php | 1 - .../wp-reactjs-starter/src/inc/view/index.php | 1 - .../src/inc/view/menu/index.php | 1 - .../src/inc/view/widget/index.php | 1 - yarn.lock | 17 ++--- 13 files changed, 80 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 5b579b6..d6ae8c0 100755 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "files": "*.php", "options": { "singleQuote": true, + "trailingCommaPHP": false, "braceStyle": "1tbs" } } @@ -136,7 +137,7 @@ "devDependencies": { "@commitlint/cli": "^8.3.5", "@commitlint/config-conventional": "^8.3.4", - "@prettier/plugin-php": "^0.13.0", + "@prettier/plugin-php": "^0.14.0", "@prettier/plugin-xml": "^0.7.2", "@types/grunt": "^0.4.25", "@types/rimraf": "^3.0.0", diff --git a/packages/utils/src/Assets.php b/packages/utils/src/Assets.php index 4b6f891..f650296 100755 --- a/packages/utils/src/Assets.php +++ b/packages/utils/src/Assets.php @@ -184,7 +184,7 @@ protected function enqueue( continue; } - $useSrc = (is_array($s) ? $s[1] : $s); + $useSrc = is_array($s) ? $s[1] : $s; $publicSrc = $publicFolder . $useSrc; $path = path_join($this->getPluginConstant(PluginReceiver::$PLUGIN_CONST_PATH), $publicSrc); if (file_exists($path)) { @@ -302,7 +302,15 @@ public function enqueueLibraryStyle($handle, $src, $deps = [], $media = 'all') { protected function probablyEnqueueComposerChunk($handle, $src, &$deps, $in_footer, $media) { $rootSlug = $this->getPluginConstant(PluginReceiver::$PLUGIN_CONST_ROOT_SLUG); $scriptSuffix = $src === 'index.js' || $src === 'index.css' ? '' : '-' . pathinfo($src, PATHINFO_FILENAME); - $handle = $this->enqueueComposer($handle, 'vendor~' . $src, $deps, 'script', $in_footer, $media, 'vendor~' . $rootSlug . '-' . $handle . $scriptSuffix); + $handle = $this->enqueueComposer( + $handle, + 'vendor~' . $src, + $deps, + 'script', + $in_footer, + $media, + 'vendor~' . $rootSlug . '-' . $handle . $scriptSuffix + ); if ($handle !== false) { array_push($deps, $handle); } diff --git a/packages/utils/test/phpunit/AssetsTest.php b/packages/utils/test/phpunit/AssetsTest.php index 156185c..e8fd861 100755 --- a/packages/utils/test/phpunit/AssetsTest.php +++ b/packages/utils/test/phpunit/AssetsTest.php @@ -339,7 +339,10 @@ public function testEnqueueMobx() { public function testProbablyEnqueueChunk() { $deps = ['jquery']; - $this->assets->shouldAllowMockingProtectedMethods()->shouldReceive('probablyEnqueueChunk')->passthru(); + $this->assets + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('probablyEnqueueChunk') + ->passthru(); $this->assets ->shouldReceive('enqueue') ->once() @@ -355,7 +358,10 @@ public function testProbablyEnqueueChunk() { public function testProbablyEnqueueChunkFromLib() { $deps = ['jquery']; - $this->assets->shouldAllowMockingProtectedMethods()->shouldReceive('probablyEnqueueChunk')->passthru(); + $this->assets + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('probablyEnqueueChunk') + ->passthru(); $this->assets->shouldNotReceive('enqueue'); $method = new ReflectionMethod(AssetsImpl::class, 'probablyEnqueueChunk'); @@ -367,7 +373,10 @@ public function testProbablyEnqueueChunkFromLib() { public function testProbablyEnqueueChunkFailing() { $deps = ['jquery']; - $this->assets->shouldAllowMockingProtectedMethods()->shouldReceive('probablyEnqueueChunk')->passthru(); + $this->assets + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('probablyEnqueueChunk') + ->passthru(); $this->assets ->shouldReceive('enqueue') ->once() @@ -407,7 +416,10 @@ public function testEnqueue() { ->shouldReceive('getCachebusterVersion') ->with($publicFolder . $script, false) ->andReturn($version); - $this->assets->shouldReceive('probablyEnqueueChunk')->once()->with($should, false, $script, [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueChunk') + ->once() + ->with($should, false, $script, [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -478,7 +490,10 @@ public function testEnqueueWithLib() { ->shouldReceive('getCachebusterVersion') ->with($publicFolder . $script, $isLib) ->andReturn($version); - $this->assets->shouldReceive('probablyEnqueueChunk')->once()->with($handle, true, $script, [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueChunk') + ->once() + ->with($handle, true, $script, [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -521,7 +536,10 @@ public function testEnqueueWithSrcArray() { ->with($publicFolder . $script, false) ->andReturn($version); - $this->assets->shouldReceive('probablyEnqueueChunk')->once()->with($should, false, $script, [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueChunk') + ->once() + ->with($should, false, $script, [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -567,7 +585,10 @@ public function testEnqueueWithComplexSrcArray() { ->shouldReceive('getCachebusterVersion') ->with($publicFolder . $script, false) ->andReturn($version); - $this->assets->shouldReceive('probablyEnqueueChunk')->once()->with($should, false, $script, [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueChunk') + ->once() + ->with($should, false, $script, [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -647,7 +668,10 @@ public function testEnqueueWithScriptParameters() { ]); $this->assets->shouldReceive('getCachebusterVersion')->andReturn($version); - $this->assets->shouldReceive('probablyEnqueueChunk')->once()->with($should, false, $script, $deps, $in_footer, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueChunk') + ->once() + ->with($should, false, $script, $deps, $in_footer, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -812,7 +836,10 @@ public function testEnqueueLibraryStyleWithParameters() { public function testProbablyEnqueueComposerChunk() { $deps = ['jquery']; - $this->assets->shouldAllowMockingProtectedMethods()->shouldReceive('probablyEnqueueComposerChunk')->passthru(); + $this->assets + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('probablyEnqueueComposerChunk') + ->passthru(); $this->assets ->shouldReceive('enqueueComposer') ->once() @@ -828,7 +855,10 @@ public function testProbablyEnqueueComposerChunk() { public function testProbablyEnqueueComposerChunkFailing() { $deps = ['jquery']; - $this->assets->shouldAllowMockingProtectedMethods()->shouldReceive('probablyEnqueueComposerChunk')->passthru(); + $this->assets + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('probablyEnqueueComposerChunk') + ->passthru(); $this->assets ->shouldReceive('enqueueComposer') ->once() @@ -876,7 +906,10 @@ public function testEnqueueComposer() { redefine('filemtime', always($ts)); redefine('file_get_contents', always('{"version": "' . $packageJsonVersion . '"}')); - $this->assets->shouldReceive('probablyEnqueueComposerChunk')->once()->with($handle, 'index.js', [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueComposerChunk') + ->once() + ->with($handle, 'index.js', [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -921,7 +954,10 @@ public function testEnqueueComposerInLernaRepo() { redefine('filemtime', always($ts)); redefine('file_get_contents', always('{"version": "' . $packageJsonVersion . '"}')); - $this->assets->shouldReceive('probablyEnqueueComposerChunk')->once()->with($handle, 'index.js', [], true, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueComposerChunk') + ->once() + ->with($handle, 'index.js', [], true, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -1083,7 +1119,10 @@ public function testEnqueueComposerWithScriptParameters() { redefine('filemtime', always($ts)); redefine('file_get_contents', always('{"version": "' . $packageJsonVersion . '"}')); - $this->assets->shouldReceive('probablyEnqueueComposerChunk')->once()->with($handle, $src, $deps, $in_footer, 'all'); + $this->assets + ->shouldReceive('probablyEnqueueComposerChunk') + ->once() + ->with($handle, $src, $deps, $in_footer, 'all'); WP_Mock::userFunction('wp_enqueue_script', [ 'times' => 1, @@ -1187,7 +1226,11 @@ public function testSetLazyScriptTranslations() { $this->assets->shouldReceive('setLazyScriptTranslations')->passthru(); - WP_Mock::userFunction('load_script_textdomain', ['times' => 1, 'args' => [PHPUNIT_SLUG, PHPUNIT_TD, $path], 'return' => '[]']); + WP_Mock::userFunction('load_script_textdomain', [ + 'times' => 1, + 'args' => [PHPUNIT_SLUG, PHPUNIT_TD, $path], + 'return' => '[]' + ]); WP_Mock::userFunction('wp_add_inline_script', ['times' => 1, 'args' => [PHPUNIT_SLUG, $script, 'before']]); $this->assets->setLazyScriptTranslations(PHPUNIT_SLUG, PHPUNIT_TD, $path); diff --git a/plugins/wp-reactjs-starter/src/inc/Assets.php b/plugins/wp-reactjs-starter/src/inc/Assets.php index 33b24be..7feba06 100644 --- a/plugins/wp-reactjs-starter/src/inc/Assets.php +++ b/plugins/wp-reactjs-starter/src/inc/Assets.php @@ -35,14 +35,7 @@ public function enqueue_scripts_and_styles($type) { // Your assets implementation here... See utils Assets for enqueue* methods // $useNonMinifiedSources = $this->useNonMinifiedSources(); // Use this variable if you need to differ between minified or non minified sources // Our utils package relies on jQuery, but this shouldn't be a problem as the most themes still use jQuery (might be replaced with https://github.com/github/fetch) - $scriptDeps = [ - self::$HANDLE_REACT, - self::$HANDLE_REACT_DOM, - self::$HANDLE_MOBX, - 'moment', - 'wp-i18n', - 'jquery' - ]; + $scriptDeps = [self::$HANDLE_REACT, self::$HANDLE_REACT_DOM, self::$HANDLE_MOBX, 'moment', 'wp-i18n', 'jquery']; // Enqueue external utils package $handleUtils = $this->enqueueComposerScript('utils', $scriptDeps); diff --git a/plugins/wp-reactjs-starter/src/inc/base/index.php b/plugins/wp-reactjs-starter/src/inc/base/index.php index 0f0dd42..49d255d 100644 --- a/plugins/wp-reactjs-starter/src/inc/base/index.php +++ b/plugins/wp-reactjs-starter/src/inc/base/index.php @@ -1,2 +1 @@ = 8" -"@prettier/plugin-php@^0.13.0": - version "0.13.0" - resolved "https://registry.yarnpkg.com/@prettier/plugin-php/-/plugin-php-0.13.0.tgz#4d4a4b9a141cf5bae141152d332682e02ec9ebc7" - integrity sha512-mcEmjmU6paeltl9M94jbazRXpFWo9r1negDBttJFVdorgD/IjaO+hUCzo0AZit++Y38e8T903MfdpD+V7Xfi3A== +"@prettier/plugin-php@^0.14.0": + version "0.14.0" + resolved "https://registry.yarnpkg.com/@prettier/plugin-php/-/plugin-php-0.14.0.tgz#299d4dab3a6943fedf3db78eadb07debc9a78a0a" + integrity sha512-aUHD08hly/mBFMZlQbXZoA+k4DixiWZACLzT4Mz90qK6nlkw9TbPaby11m8OIwXcyUQRW6BeZ6hk209TbPxraQ== dependencies: linguist-languages "^7.5.1" mem "^6.0.1" - php-parser glayzzle/php-parser#4e9d584c7bd478175777e643e8d9d57d1863023a + php-parser "3.0.0" "@prettier/plugin-xml@^0.7.2": version "0.7.2" @@ -11422,9 +11422,10 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -php-parser@glayzzle/php-parser#4e9d584c7bd478175777e643e8d9d57d1863023a: - version "3.0.0-prerelease.9" - resolved "https://codeload.github.com/glayzzle/php-parser/tar.gz/4e9d584c7bd478175777e643e8d9d57d1863023a" +php-parser@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.0.0.tgz#7e0abef4941cabbf10f25f1445bca0f758f5102f" + integrity sha512-WqGNf8Y5LBOXKJz9eKMwxjqfJ7KnwVU7DH3ebPTaOLlPtVrig++zG8KoOXywY9V9jQxY+wOY0EtC/e+wamaxsQ== picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.0.7: version "2.2.1"