Widget::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Ffcms\Core\Arch;
4
5
use Apps\ActiveRecord\App as AppRecord;
0 ignored issues
show
Bug introduced by
The type Apps\ActiveRecord\App 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...
6
use Ffcms\Core\App;
7
use Ffcms\Core\Helper\Type\Any;
8
use Ffcms\Core\Helper\Type\Str;
9
use Ffcms\Core\Interfaces\iWidget;
10
11
/**
12
 * Class Widget. Provide constructor to work with widget-type based extensions for ffcms.
13
 * @package Ffcms\Core\Arch
14
 */
15
class Widget implements iWidget
16
{
17
    /** @var string|null */
18
    public static $class;
19
    
20
    public static $view;
21
    public static $request;
22
    public static $response;
23
24
    /**
25
     * Build and display widget
26
     * @param array|null $params
27
     * @return null|string
28
     */
29
    public static function widget(?array $params = null): ?string
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
30
    {
31
        self::$class = get_called_class();
32
        self::$view = App::$View;
33
        self::$request = App::$Request;
34
        self::$response = App::$Response;
35
36
        // check if class exist
37
        if (!class_exists(self::$class)) {
38
            return 'Error: Widget is not founded: ' . self::$class;
39
        }
40
41
        /** @var iWidget $object */
42
        $object = new self::$class;
43
        if (Any::isArray($params) && count($params) > 0) {
44
            foreach ($params as $property => $value) {
45
                if (property_exists($object, $property)) {
46
                    $object->{$property} = $value;
47
                }
48
            }
49
        }
50
51
        // initialize widget
52
        $object->init();
53
        return $object->display();
54
    }
55
56
    /**
57
     * Get widget configs from admin part as array $cfg=>$value
58
     * @return array|null
59
     */
60
    public function getConfigs(): ?array
61
    {
62
        $realName = Str::lastIn(self::$class, '\\', true);
63
        return AppRecord::getConfigs('widget', $realName);
64
    }
65
66
    public function display(): ?string
67
    {
68
    }
69
70
    public function init(): void
71
    {
72
    }
73
74
    /**
75
     * Check if widget is enabled. For native widget is always enabled
76
     * @param string|null $name
77
     * @return bool
78
     */
79
    public static function enabled(?string $name = null): bool
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

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

79
    public static function enabled(/** @scrutinizer ignore-unused */ ?string $name = null): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        return true;
82
    }
83
}
84