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

OptimizeImages::process()   B

Complexity

Conditions 6
Paths 11

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 8.2068
c 0
b 0
f 0
cc 6
nc 11
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Spatie\ImageOptimizer\OptimizerChainFactory;
12
13
/**
14
 * Images Optimization.
15
 */
16
class OptimizeImages extends AbstractStepOptimize
17
{
18
    public function setProcessor()
19
    {
20
        $this->type = 'images';
21
        $this->processor = OptimizerChainFactory::create();
22
    }
23
24
    public function processFile(\Symfony\Component\Finder\SplFileInfo $file)
25
    {
26
        $this->processor->optimize($file->getPathname());
0 ignored issues
show
Bug introduced by
The method optimize does only exist in Spatie\ImageOptimizer\OptimizerChain, but not in WyriHaximus\HtmlCompress\Parser.

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...
27
    }
28
}
29