BaseBlock::Collection()   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 LeKoala\Blocks;
4
5
use SilverStripe\Core\ClassInfo;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\View\ArrayData;
8
use SilverStripe\View\ViewableData;
9
10
/**
11
 * This is the class you need to extend to create your own block
12
 *
13
 * Also see BlocksCreateTask to create to blocks for you
14
 */
15
class BaseBlock extends ViewableData
16
{
17
    /**
18
     * @var Block
19
     */
20
    protected $_block;
21
22
    public function __construct(Block $block)
23
    {
24
        $this->_block = $block;
25
26
        // Allow calling base blocks methods (like Images, etc)
27
        $this->customise($block);
28
29
        // Allow calling any extra stuff on our block
30
        $data = $block->DataArray();
31
        $settings = $block->SettingsArray();
32
        $extra = $this->ExtraData();
33
        $arrayData = new ArrayData(array_merge($data, $settings, $extra));
34
35
        $this->setFailover($arrayData);
36
    }
37
38
    /**
39
     * Allow direct queries from the template
40
     *
41
     * Use wisely...
42
     *
43
     * @param string $class
44
     * @return DataList
0 ignored issues
show
Bug introduced by
The type LeKoala\Blocks\DataList 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...
45
     */
46
    public function Query($class)
47
    {
48
        // Allow unqualified classes
49
        if (!class_exists($class)) {
50
            $subclasses = ClassInfo::subclassesFor(DataObject::class);
51
            foreach ($subclasses as $lcName => $name) {
52
                $nameClass = Block::getClassWithoutNamespace($name);
53
                if ($class == $nameClass) {
54
                    $class = $name;
55
                    break;
56
                }
57
            }
58
        }
59
        return $class::get();
60
    }
61
62
    public function updateFields(BlockFieldList $fields)
0 ignored issues
show
Unused Code introduced by
The parameter $fields 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

62
    public function updateFields(/** @scrutinizer ignore-unused */ BlockFieldList $fields)

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...
63
    {
64
    }
65
66
    public function updateClass(&$class)
0 ignored issues
show
Unused Code introduced by
The parameter $class 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

66
    public function updateClass(/** @scrutinizer ignore-unused */ &$class)

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...
67
    {
68
    }
69
70
    /**
71
     * Extra data to feed to the template
72
     * @return array
73
     */
74
    public function ExtraData()
75
    {
76
        return [];
77
    }
78
79
    /**
80
     * @return DataList
81
     */
82
    public function Collection()
83
    {
84
    }
85
86
    /**
87
     * @return DataList
88
     */
89
    public function SharedCollection()
90
    {
91
    }
92
}
93