Passed
Push — master ( 0e4a9e...1c63d3 )
by Evgenii
01:14
created

bootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helick\Blocks;
4
5
use Helick\Blocks\Contracts\Bootable;
6
use Helick\Blocks\Contracts\Composable;
7
8
/**
9
 * Get the list of registered blocks.
10
 *
11
 * @param array $blocks
12
 *
13
 * @return array
14
 */
15
function blocks(array $blocks = []): array
16
{
17
    /**
18
     * Control the list of registered blocks.
19
     *
20
     * @param array $blocks
21
     */
22
    $blocks = apply_filters('helick_blocks', $blocks);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

22
    $blocks = /** @scrutinizer ignore-call */ apply_filters('helick_blocks', $blocks);
Loading history...
23
24
    $blocks = array_filter((array)$blocks, function (string $class) {
25
        return $class instanceof Composable;
26
    });
27
28
    $blocks = array_unique($blocks);
29
30
    return $blocks;
31
}
32
33
/**
34
 * Bootstrap the given blocks.
35
 *
36
 * @param array $blocks
37
 *
38
 * @return void
39
 */
40
function bootstrap(array $blocks): void
41
{
42
    $blocks = array_filter($blocks, function (string $class) {
43
        return $class instanceof Bootable;
44
    });
45
46
    array_walk($blocks, static function (Bootable $block) {
47
        $block::boot();
48
    });
49
}
50