Issues (1519)

system/Inji/Statics.php (3 issues)

1
<?php
2
namespace Inji;
3
/**
4
 * Statics
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class Statics {
12
13
    /**
14
     * Cached static file and return absolute url for client side use
15
     *
16
     * @param string $path
17
     * @param string $resize
18
     * @param string $resizeCrop
19
     * @param string $resizePos
20
     * @return string
21
     */
22
    public static function file($path, $resize = '', $resizeCrop = '', $resizePos = '', $pathAbsolute = false) {
23
        if (!$path) {
24
            $pathAbsolute = false;
25
            $path = !empty(App::$primary->config['site']['noimage']) ? App::$primary->config['site']['noimage'] : '/static/system/images/no-image.png';
26
        }
27
28
        $absolutePath = $pathAbsolute ? $path : App::$cur->staticLoader->parsePath($path);
0 ignored issues
show
Bug Best Practice introduced by
The property staticLoader does not exist on Inji\App. Since you implemented __get, consider adding a @property annotation.
Loading history...
The method parsePath() does not exist on Inji\Module. It seems like you code against a sub-type of Inji\Module such as Inji\StaticLoader or Inji\Db. ( Ignorable by Annotation )

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

28
        $absolutePath = $pathAbsolute ? $path : App::$cur->staticLoader->/** @scrutinizer ignore-call */ parsePath($path);
Loading history...
The method parsePath() 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

28
        $absolutePath = $pathAbsolute ? $path : App::$cur->staticLoader->/** @scrutinizer ignore-call */ parsePath($path);

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...
29
30
        $convert = false;
31
        if (!file_exists($absolutePath) && file_exists(mb_convert_encoding($absolutePath, 'Windows-1251', 'UTF-8'))) {
32
            $absolutePath = mb_convert_encoding($absolutePath, 'Windows-1251', 'UTF-8');
33
            $convert = true;
34
        }
35
        if (!file_exists($absolutePath)) {
36
            return '';
37
        } else {
38
            $options = [];
39
            if ($resize) {
40
                $resize = explode('x', $resize);
41
                $options = ['resize' => ['x' => $resize[0], 'y' => $resize[1]]];
42
            }
43
            $options['crop'] = $resizeCrop;
44
            $options['pos'] = $resizePos;
45
            $path = Cache::file($absolutePath, $options);
46
            $path = $convert ? mb_convert_encoding($path, 'UTF-8', 'Windows-1251') : $path;
47
            return '/' . $path;
48
        }
49
    }
50
}