jonathanmaron /
ctw-middleware-htmlminifier
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | |||
| 4 | namespace Ctw\Middleware\HtmlMinifierMiddleware\Adapter\WyriHaximusAdapter; |
||
| 5 | |||
| 6 | use Ctw\Middleware\HtmlMinifierMiddleware\Adapter\AdapterInterface; |
||
| 7 | use voku\helper\HtmlMin; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use WyriHaximus\HtmlCompress\Factory; |
||
|
0 ignored issues
–
show
The type
WyriHaximus\HtmlCompress\Factory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 9 | |||
| 10 | class WyriHaximusAdapter extends AbstractWyriHaximusAdapter implements AdapterInterface |
||
| 11 | { |
||
| 12 | public function minify(string $htmlSource): string |
||
| 13 | { |
||
| 14 | /** @phpstan-ignore class.notFound */ |
||
| 15 | $htmlMin = new HtmlMin(); |
||
| 16 | |||
| 17 | $httpHost = ''; |
||
| 18 | if (isset($_SERVER['HTTP_HOST'])) { |
||
| 19 | $httpHost = $_SERVER['HTTP_HOST']; |
||
| 20 | } |
||
| 21 | |||
| 22 | // optimize html via "HtmlDomParser()" |
||
| 23 | // $htmlMin->doOptimizeViaHtmlDomParser(); |
||
| 24 | |||
| 25 | // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)") |
||
| 26 | // $htmlMin->doRemoveComments(); |
||
| 27 | |||
| 28 | // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)") |
||
| 29 | // $htmlMin->doSumUpWhitespace(); |
||
| 30 | |||
| 31 | // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)") |
||
| 32 | // $htmlMin->doRemoveWhitespaceAroundTags(); |
||
| 33 | |||
| 34 | // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)") |
||
| 35 | // $htmlMin->doOptimizeAttributes(); |
||
| 36 | |||
| 37 | // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)") |
||
| 38 | // $htmlMin->doRemoveHttpPrefixFromAttributes(); |
||
| 39 | |||
| 40 | // remove optional "https:"-prefix from attributes (depends on "doOptimizeAttributes(true)") |
||
| 41 | // $htmlMin->doRemoveHttpsPrefixFromAttributes(); |
||
| 42 | |||
| 43 | // keep "http:"- and "https:"-prefix for all external links |
||
| 44 | // $htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(); |
||
| 45 | |||
| 46 | // make some links relative, by removing the domain from attributes |
||
| 47 | $htmlMin->doMakeSameDomainsLinksRelative([$httpHost]); |
||
| 48 | |||
| 49 | // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default) |
||
| 50 | // $htmlMin->doRemoveDefaultAttributes(); |
||
| 51 | |||
| 52 | // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)") |
||
| 53 | // $htmlMin->doRemoveDeprecatedAnchorName(); |
||
| 54 | |||
| 55 | // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway |
||
| 56 | // (depends on "doOptimizeAttributes(true)") |
||
| 57 | // $htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); |
||
| 58 | |||
| 59 | // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)") |
||
| 60 | // $htmlMin->doRemoveDeprecatedTypeFromScriptTag(); |
||
| 61 | |||
| 62 | // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)") |
||
| 63 | // $htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); |
||
| 64 | |||
| 65 | // remove "type=text/css" from all links and styles |
||
| 66 | // $htmlMin->doRemoveDeprecatedTypeFromStyleAndLinkTag(); |
||
| 67 | |||
| 68 | // remove "media="all" from all links and styles |
||
| 69 | // $htmlMin->doRemoveDefaultMediaTypeFromStyleAndLinkTag(); |
||
| 70 | |||
| 71 | // remove type="submit" from button tags |
||
| 72 | // $htmlMin->doRemoveDefaultTypeFromButton(); |
||
| 73 | |||
| 74 | // remove some empty attributes (depends on "doOptimizeAttributes(true)") |
||
| 75 | // $htmlMin->doRemoveEmptyAttributes(); |
||
| 76 | |||
| 77 | // remove 'value=""' from empty <input> (depends on "doOptimizeAttributes(true)") |
||
| 78 | // $htmlMin->doRemoveValueFromEmptyInput(); |
||
| 79 | |||
| 80 | // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)") |
||
| 81 | // $htmlMin->doSortCssClassNames(); |
||
| 82 | |||
| 83 | // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)") |
||
| 84 | // $htmlMin->doSortHtmlAttributes(); |
||
| 85 | |||
| 86 | // remove more (aggressive) spaces in the dom (disabled by default) |
||
| 87 | $htmlMin->doRemoveSpacesBetweenTags(); |
||
| 88 | |||
| 89 | // remove quotes e.g. class="lall" => class=lall |
||
| 90 | $htmlMin->doRemoveOmittedQuotes(false); |
||
| 91 | |||
| 92 | // remove omitted html tags e.g. <p>lall</p> => <p>lall |
||
| 93 | // $htmlMin->doRemoveOmittedHtmlTags(); |
||
| 94 | |||
| 95 | /** @phpstan-ignore class.notFound, method.nonObject */ |
||
| 96 | $htmlModified = Factory::constructSmallest()->withHtmlMin($htmlMin)->compress($htmlSource); |
||
| 97 | assert(is_string($htmlModified)); |
||
| 98 | |||
| 99 | return $this->postProcess($htmlModified); |
||
| 100 | } |
||
| 101 | } |
||
| 102 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths