Skip to content

Commit

Permalink
style: reformat php codebase (#4gg05b)
Browse files Browse the repository at this point in the history
  • Loading branch information
matzeeable committed Apr 7, 2020
1 parent 4b70b02 commit c36b65b
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 41 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"files": "*.php",
"options": {
"singleQuote": true,
"trailingCommaPHP": false,
"braceStyle": "1tbs"
}
}
Expand All @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions packages/utils/src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
71 changes: 57 additions & 14 deletions packages/utils/test/phpunit/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions plugins/wp-reactjs-starter/src/inc/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/base/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/base/others/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

2 changes: 1 addition & 1 deletion plugins/wp-reactjs-starter/src/inc/base/others/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

require_once WPRJSS_INC . 'Core.php';
call_user_func(array(WPRJSS_NS . '\\Core', 'getInstance'));
call_user_func([WPRJSS_NS . '\\Core', 'getInstance']);
} else {
// WP REST API version not reached
require_once WPRJSS_INC . 'base/others/fallback-rest-api.php';
Expand Down
1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/rest/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/view/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/view/menu/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

1 change: 0 additions & 1 deletion plugins/wp-reactjs-starter/src/inc/view/widget/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php // Silence is golden.

17 changes: 9 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2624,14 +2624,14 @@
dependencies:
"@types/node" ">= 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"
Expand Down Expand Up @@ -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"
[email protected]:
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"
Expand Down

0 comments on commit c36b65b

Please sign in to comment.