GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a1835d...10e84a )
by
unknown
02:48
created

Widgets::get()   B

Complexity

Conditions 9
Paths 13

Size

Total Lines 56
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 33
nc 13
nop 1
dl 0
loc 56
rs 8.0555
c 0
b 0
f 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
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Http\Presenter\Repositories;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Psr\Patterns\Structural\Repository\AbstractRepository;
19
20
/**
21
 * Class Widgets
22
 *
23
 * @package O2System\Framework\Http\Presenter\Repositories
24
 */
25
class Widgets extends AbstractRepository
26
{
27
    /**
28
     * Widgets::hasWidget
29
     *
30
     * @param string $widgetOffset
31
     *
32
     * @return bool
33
     */
34
    public function hasWidget($widgetOffset)
35
    {
36
        return $this->__isset($widgetOffset);
37
    }
38
39
    // ------------------------------------------------------------------------
40
41
    /**
42
     * Widgets::load
43
     *
44
     * @param string $widgetOffset
45
     *
46
     * @return bool
47
     */
48
    public function load($widgetOffset)
49
    {
50
        $widgetDirectory = modules()->current()->getRealPath() . 'Widgets' . DIRECTORY_SEPARATOR . studlycase($widgetOffset) . DIRECTORY_SEPARATOR;
0 ignored issues
show
Bug introduced by
The method current() does not exist on O2System\Framework\Conta...s\DataStructures\Module. ( Ignorable by Annotation )

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

50
        $widgetDirectory = modules()->/** @scrutinizer ignore-call */ current()->getRealPath() . 'Widgets' . DIRECTORY_SEPARATOR . studlycase($widgetOffset) . DIRECTORY_SEPARATOR;

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...
51
52
        if (is_dir($widgetDirectory)) {
53
            $widget = new DataStructures\Module\Widget($widgetDirectory);
0 ignored issues
show
Bug introduced by
The type O2System\Framework\Http\...tructures\Module\Widget 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
            $this->store(camelcase($widgetOffset), $widget);
55
        }
56
57
        return $this->exists($widgetOffset);
58
    }
59
60
    // ------------------------------------------------------------------------
61
62
    /**
63
     * Widgets::get
64
     *
65
     * @param string $offset
66
     *
67
     * @return string
68
     */
69
    public function get($offset)
70
    {
71
        if (null !== ($widget = parent::get($offset))) {
72
73
            $widgetViewFilePath = $widget->getRealPath() . 'Views' . DIRECTORY_SEPARATOR . $offset . '.phtml';
74
75
            if (presenter()->theme->use === true) {
0 ignored issues
show
Bug introduced by
The property use does not seem to exist on O2System\Framework\Conta...Structures\Module\Theme.
Loading history...
76
                $widgetViewReplacementPath = str_replace(
77
                    $widget->getRealPath() . 'Views' . DIRECTORY_SEPARATOR,
78
                    presenter()->theme->active->getPathName() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, [
0 ignored issues
show
Bug introduced by
The property active does not seem to exist on O2System\Framework\Conta...Structures\Module\Theme.
Loading history...
79
                        'views',
80
                        'widgets',
81
                    ]) . DIRECTORY_SEPARATOR,
82
                    $widgetViewFilePath
83
                );
84
85
                $viewsFileExtensions = [
86
                    '.php',
87
                    '.phtml',
88
                ];
89
90
                // Add Theme File Extensions
91
                if (presenter()->theme->active->getPresets()->offsetExists('extension')) {
92
                    array_unshift($viewsFileExtensions,
93
                        presenter()->theme->active->getPresets()->offsetGet('extension'));
94
                } elseif (presenter()->theme->active->getPresets()->offsetExists('extensions')) {
95
                    $viewsFileExtensions = array_merge(
96
                        presenter()->theme->active->getPresets()->offsetGet('extensions'),
97
                        $viewsFileExtensions
98
                    );
99
                }
100
101
                foreach ($viewsFileExtensions as $viewsFileExtension) {
102
                    if (is_file($widgetViewReplacementPath . $viewsFileExtension)) {
103
                        $widgetViewFilePath = $widgetViewReplacementPath . $viewsFileExtension;
104
                    }
105
                }
106
107
            }
108
109
            loader()->addNamespace($widget->getNamespace(), $widget->getRealPath());
110
            $widgetPresenterClassName = $widgetPresenterClassName = $widget->getNamespace() . 'Presenters\\' . studlycase($offset);
0 ignored issues
show
Unused Code introduced by
The assignment to $widgetPresenterClassName is dead and can be removed.
Loading history...
111
112
            $widgetPresenter = new $widgetPresenterClassName();
113
114
            if (is_file($widgetViewFilePath)) {
115
                parser()->loadVars($widgetPresenter->getArrayCopy());
116
                parser()->loadFile($widgetViewFilePath);
117
118
                return parser()->parse();
119
            } elseif (method_exists($widgetPresenter, 'render')) {
120
                return $widgetPresenter->render();
121
            }
122
        }
123
124
        return null;
125
    }
126
}