Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit f6d43fe

Browse files
committed
Fixed coding standard
1 parent 1e4f531 commit f6d43fe

15 files changed

+121
-225
lines changed
File renamed without changes.

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"php library"
5555
],
5656
"autoload": {
57-
"files": [],
5857
"psr-4": {
5958
"AppSeeds\\": "src/"
6059
}
@@ -63,6 +62,7 @@
6362
"offline": "@php offline.php",
6463
"fixer": "php-cs-fixer fix --show-progress=estimating --verbose --ansi",
6564
"test": "@php tests/v2/test.php --ansi",
65+
"bf": "blackfire run php tests/v2/test.php --ansi",
6666
"assets": [
6767
"npm run js",
6868
"npm run css"
@@ -83,7 +83,6 @@
8383
"php": "^5.6 || ^7.0 || ^8.0",
8484
"ext-libxml": "*",
8585
"lib-libxml": ">=2.7.7",
86-
"glenscott/url-normalizer": "^1.0",
8786
"mrclay/jsmin-php": "^2.0",
8887
"psr/simple-cache": "^1.0",
8988
"symfony/css-selector": "^2.0 || ^3.0 || ^4.0 || ^5.0",

composer.lock

Lines changed: 1 addition & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"@shinsenter/defer.js": "^1.1.15"
77
},
88
"devDependencies": {
9-
"clean-css-cli": "^4.3.0",
10-
"uglify-js": "^3.12.6"
9+
"clean-css-cli": "latest",
10+
"uglify-js": "latest"
1111
},
1212
"scripts": {
1313
"css": "cleancss -o public/styles.min.css assets/styles.css",
14-
"js": "uglifyjs --config-file .uglifyjs -o public/helpers.min.js assets/helpers.js"
14+
"js": "uglifyjs --config-file assets/.uglifyjs -o public/helpers.min.js assets/helpers.js"
1515
}
1616
}

src/Defer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ public function toHtml()
179179
*/
180180
public function optimize()
181181
{
182-
$dom = $this->document;
182+
$dom = $this->document;
183+
$html = $dom->root();
183184

184185
// Skip if already _optimized
185-
if ($this->_optimized || empty($html = $dom->root())) {
186+
if ($this->_optimized || empty($html)) {
186187
return $this;
187188
}
188189

src/Helpers/DeferAssetUtil.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
namespace AppSeeds\Helpers;
1919

20-
use URL\Normalizer as URLNormalizer;
21-
2220
class DeferAssetUtil
2321
{
2422
/**
@@ -81,14 +79,6 @@ public static function normalizeUrl($url)
8179
$url = 'https:' . $url;
8280
}
8381

84-
if (preg_match('#^https?://#i', $url)) {
85-
try {
86-
return (new URLNormalizer($url, true, true))->normalize();
87-
} catch (\Exception $th) {
88-
unset($th);
89-
}
90-
}
91-
9282
return $url;
9383
}
9484

src/Helpers/DeferJs.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,17 @@ public function getFromCache()
294294
$key = $this->cacheKey();
295295

296296
if (!$this->cache()->has($key)) {
297-
if (empty($defer = $this->makeOffline($key))
298-
&& empty($defer = @file_get_contents(DeferConstant::SRC_DEFERJS_FALLBACK))) {
299-
throw new DeferException('Could not load defer.js library! Please check your configuration.');
300-
}
297+
$defer = $this->makeOffline($key);
298+
299+
if (empty($defer)) {
300+
$defer = @file_get_contents(DeferConstant::SRC_DEFERJS_FALLBACK);
301301

302-
return $defer;
302+
if (empty($defer)) {
303+
throw new DeferException('Could not load defer.js library! Please check your configuration.');
304+
}
305+
306+
return $defer;
307+
}
303308
}
304309

305310
return $this->cache()->get($key);
@@ -316,8 +321,13 @@ public function getFromCache()
316321
*/
317322
public function makeOffline($key = null, $duration = 9999999999)
318323
{
319-
if (empty($this->deferjs_src)
320-
|| empty($defer = @file_get_contents($this->deferjs_src))) {
324+
if (empty($this->deferjs_src)) {
325+
return false;
326+
}
327+
328+
$defer = @file_get_contents($this->deferjs_src);
329+
330+
if (empty($defer)) {
321331
return false;
322332
}
323333

src/Helpers/DeferOptimizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ public static function optimizeDocument(DocumentNode &$doc, DeferOptions &$optio
3737
{
3838
// Normalize entire document, add missing <head> and <body> tags
3939
$doc->normalize();
40+
$isAmp = $doc->isAmpHtml();
4041

4142
// Get the root HTML tag
4243
$html = $doc->root();
4344
$body = $doc->body();
4445

4546
// Set AMP options if it is an AMP page
46-
if ($isAmp = $doc->isAmpHtml()) {
47+
if ($isAmp) {
4748
$options->backup();
4849
$options->forAmp();
4950
}

src/Resolvers/DeferResolver.php

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class DeferResolver
4545
*/
4646
protected $attr_backups = [];
4747

48+
/**
49+
* @property $fallback Hold the noscript instance
50+
*/
51+
protected $fallback;
52+
4853
/**
4954
* Constructor
5055
*/
@@ -65,7 +70,9 @@ public function __call($method, $parameters)
6570
return $this->node->{$method}(...$parameters);
6671
}
6772

68-
if (method_exists($dom = $this->node->document(), $method)) {
73+
$dom = $this->node->document();
74+
75+
if (method_exists($dom, $method)) {
6976
return $dom->{$method}(...$parameters);
7077
}
7178
}
@@ -86,40 +93,27 @@ public static function resolver(ElementNode &$node, DeferOptions $options)
8693
switch ($node->tagName()) {
8794
case 'link':
8895
return new LinkResolver($node, $options);
89-
break;
90-
9196
case 'meta':
9297
return new MetaResolver($node, $options);
93-
break;
94-
9598
case 'style':
9699
return new StyleResolver($node, $options);
97-
break;
98-
99100
case 'script':
100101
return new ScriptResolver($node, $options);
101-
break;
102-
103102
case 'embed':
104103
case 'frame':
105104
case 'iframe':
106105
return new IframeResolver($node, $options);
107-
break;
108-
109106
case 'img':
110107
case 'picture':
111108
case 'video':
112109
case 'audio':
113110
case 'source':
114111
return new MediaResolver($node, $options);
115-
break;
116-
117112
case 'input':
118113
if (strtolower($node->getAttribute('type')) == 'image') {
119114
return new MediaResolver($node, $options);
120115
}
121116
break;
122-
123117
default:
124118
if ($node->hasAttribute('style')) {
125119
return new InlineStyleResolver($node, $options);
@@ -136,6 +130,23 @@ public static function resolver(ElementNode &$node, DeferOptions $options)
136130
|--------------------------------------------------------------------------
137131
*/
138132

133+
public function resolveNoScript()
134+
{
135+
if ($this->fallback) {
136+
return $this->fallback;
137+
}
138+
139+
if (empty($fallback)) {
140+
$fallback = $this->newNode('noscript');
141+
}
142+
143+
$clone = $this->node->cloneNode(true);
144+
$fallback->prependWith($clone);
145+
$this->fallback = $fallback;
146+
147+
return $this->fallback;
148+
}
149+
139150
/**
140151
* Returns the node or parent if parent is a <noscript>
141152
*
@@ -215,20 +226,26 @@ public function hasLazyloadFlag()
215226
*/
216227
public function skipLazyloading($attr = 'src')
217228
{
218-
if (!empty($this->options->ignore_lazyload_paths)
219-
&& !empty($value = $this->node->getAttribute($attr))) {
220-
foreach ($this->options->ignore_lazyload_paths as $keyword) {
221-
if (strstr($value, $keyword) !== true) {
222-
return true;
229+
if (!empty($this->options->ignore_lazyload_paths)) {
230+
$value = $this->node->getAttribute($attr);
231+
232+
if (!empty($value)) {
233+
foreach ($this->options->ignore_lazyload_paths as $keyword) {
234+
if (strstr($value, $keyword) !== true) {
235+
return true;
236+
}
223237
}
224238
}
225239
}
226240

227-
if (!empty($this->options->ignore_lazyload_texts)
228-
&& !empty($text = $this->node->getText())) {
229-
foreach ($this->options->ignore_lazyload_texts as $keyword) {
230-
if (strstr($text, $keyword) !== true) {
231-
return true;
241+
if (!empty($this->options->ignore_lazyload_texts)) {
242+
$text = $this->node->getText();
243+
244+
if (!empty($text)) {
245+
foreach ($this->options->ignore_lazyload_texts as $keyword) {
246+
if (strstr($text, $keyword) !== true) {
247+
return true;
248+
}
232249
}
233250
}
234251
}
@@ -274,9 +291,12 @@ public function resolveAttr($attr, $attributes = [])
274291

275292
foreach ($attributes as $from_attr) {
276293
if (is_string($from_attr) && $this->node->hasAttribute($from_attr)) {
277-
if (!empty($tmp = $this->node->getAttribute($from_attr))) {
294+
$tmp = $this->node->getAttribute($from_attr);
295+
296+
if (!empty($tmp)) {
278297
$unified = $tmp;
279298
}
299+
280300
$this->node->removeAttribute($from_attr);
281301
}
282302
}

0 commit comments

Comments
 (0)