FileHelper::thumb()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 4
nop 3
1
<?php
2
namespace File\View\Helper;
3
4
use Cake\View\Helper;
5
6
class FileHelper extends Helper
7
{
8
9
    /**
10
     * {@inheritDoc}
11
     */
12
    public $helpers = [
13
        'Html',
14
    ];
15
16
    /**
17
     * Thumb image.
18
     *
19
     * @param string|array $path Path to the image file, relative to the app/webroot/img/ direct.
20
     * @param array $options Array of HTML attributes. See above for special options.
21
     * @param string $thumb Name of thumb.
22
     * @return string completed img tag.
23
     * @see https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images
24
     */
25
    public function thumb($path, array $options = [], string $thumb = 'default'): string
26
    {
27
        if ($thumb !== 'default') {
28
            $path = preg_replace('/default/', $thumb, $path);
29
        }
30
31
        if (!is_array($options)) {
0 ignored issues
show
introduced by
The condition is_array($options) is always true.
Loading history...
32
            $options = [];
33
        }
34
35
        return $this->Html->image($path, $options);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->Html->image($path, $options) targeting Cake\View\Helper::__call() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The method image() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        return $this->Html->/** @scrutinizer ignore-call */ image($path, $options);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property Html does not exist on File\View\Helper\FileHelper. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The expression return $this->Html->image($path, $options) returns the type null which is incompatible with the type-hinted return string.
Loading history...
36
    }
37
}
38