Completed
Pull Request — master (#5)
by David
02:51
created

CmsPageExtension::getCmsBlocksById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheCodingMachine\CMS\StaticRegistry\Twig;
5
6
use Barclays\Dao\BaseBlockDao;
0 ignored issues
show
Bug introduced by
The type Barclays\Dao\BaseBlockDao 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...
7
use Barclays\Dao\StaticBlockDao;
0 ignored issues
show
Bug introduced by
The type Barclays\Dao\StaticBlockDao 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...
8
use Barclays\Model\BaseBlock;
0 ignored issues
show
Bug introduced by
The type Barclays\Model\BaseBlock 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...
9
use Barclays\Model\PageVersion;
0 ignored issues
show
Bug introduced by
The type Barclays\Model\PageVersion 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...
10
use Barclays\Services\SerializationContext;
0 ignored issues
show
Bug introduced by
The type Barclays\Services\SerializationContext 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...
11
use TheCodingMachine\CMS\StaticRegistry\Loaders\Block;
12
use TheCodingMachine\CMS\StaticRegistry\Loaders\Page;
13
use TheCodingMachine\CMS\StaticRegistry\Registry\BlockRegistry;
14
use TheCodingMachine\CMS\StaticRegistry\Registry\PageRegistry;
15
use TheCodingMachine\TDBM\UncheckedOrderBy;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\UncheckedOrderBy 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...
16
17
class CmsPageExtension extends \Twig_Extension
18
{
19
    /**
20
     * @var PageRegistry
21
     */
22
    private $pageRegistry;
23
    /**
24
     * @var BlockRegistry
25
     */
26
    private $blockRegistry;
27
28
    public function __construct(PageRegistry $pageRegistry, BlockRegistry $blockRegistry)
29
    {
30
        $this->pageRegistry = $pageRegistry;
31
        $this->blockRegistry = $blockRegistry;
32
    }
33
34
    /**
35
     * Returns a list of functions to add to the existing list.
36
     *
37
     * @return \Twig_Function[]
38
     */
39
    public function getFunctions()
40
    {
41
        return [
42
            new \Twig_Function('cmsBlocksById', [$this, 'getCmsBlocksById']),
43
            new \Twig_Function('cmsPagesByTag', [$this, 'getCmsPagesByTag']),
44
        ];
45
    }
46
47
    /**
48
     * @return Block[]
49
     */
50
    public function getCmsBlocksById(string $blockId): array
51
    {
52
        $blocks = $this->blockRegistry->getBlocks($blockId);
53
54
        return $blocks;
55
    }
56
57
    /**
58
     * @return Page[]
59
     */
60
    public function getCmsPagesByTag(string $tag, ?string $domain = null, string $orderBy = 'date', string $direction = 'desc', int $limit = null, int $page = null): array
0 ignored issues
show
Unused Code introduced by
The parameter $limit 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

60
    public function getCmsPagesByTag(string $tag, ?string $domain = null, string $orderBy = 'date', string $direction = 'desc', /** @scrutinizer ignore-unused */ int $limit = null, int $page = null): array

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...
Unused Code introduced by
The parameter $page 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

60
    public function getCmsPagesByTag(string $tag, ?string $domain = null, string $orderBy = 'date', string $direction = 'desc', int $limit = null, /** @scrutinizer ignore-unused */ int $page = null): array

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...
61
    {
62
        if (!in_array($direction, ['asc', 'desc'])) {
63
            return ["Error while using getCmsPagesByTag. The third parameter (direction) must be either 'asc' or 'desc'."];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('Error whil...ther 'asc' or 'desc'.') returns the type array<integer,string> which is incompatible with the documented return type TheCodingMachine\CMS\StaticRegistry\Loaders\Page[].
Loading history...
64
        }
65
66
        $pages = $this->pageRegistry->findPagesByTag($tag, $domain);
67
68
        /*if ($limit !== null || $page !== null) {
69
            $blocks = $blocks->take(($page !== null) ? $page*$limit : null, $limit);
70
            $count = $blocks->totalCount();
71
        } else {
72
            $count = $blocks->count();
73
        }*/
74
75
76
        return $pages;
77
    }
78
}
79