Completed
Push — optimize ( 1cb82b...432add )
by Arnaud
02:20 queued 14s
created

OptimizeHtml::setProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Step;
10
11
use WyriHaximus\HtmlCompress\Factory;
12
13
/**
14
 * HTML files Optimization.
15
 */
16
class OptimizeHtml extends AbstractStepOptimize
17
{
18
    public function setProcessor()
19
    {
20
        $this->type = 'html';
21
        $this->processor = Factory::construct();
22
    }
23
24
    public function processFile(\Symfony\Component\Finder\SplFileInfo $file)
25
    {
26
        $html = file_get_contents($file->getPathname());
27
        $htmlCompressed = $this->processor->compress($html);
0 ignored issues
show
Bug introduced by
The method compress does only exist in WyriHaximus\HtmlCompress\Parser, but not in Spatie\ImageOptimizer\OptimizerChain.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
28
        \Cecil\Util::getFS()->dumpFile($file->getPathname(), $htmlCompressed);
29
    }
30
}
31