PageHelper::pageBySlug()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 3
nc 2
nop 3
1
<?php
2
/**
3
 * @author Oleksandr Torosh <[email protected]>
4
 */
5
6
namespace Page\Model\Helper;
7
8
use Application\Cache\Keys;
9
use Page\Model\Page;
10
11
class PageHelper extends Page
12
{
13
14
    public function pageBySlug($slug, $lang = null, $lifeTime = 60)
15
    {
16
        $lang = ($lang) ? $lang : LANG;
17
18
        $pageResult = $this->getDi()->get('cacheManager')->load([
0 ignored issues
show
Bug introduced by
The method get cannot be called on $this->getDi() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
19
            Keys::PAGE,
20
            $slug,
21
            $lang
22
23
        ], function() use ($slug, $lang, $lifeTime) {
24
            $columns = ['p.*'];
25
            foreach($this->translateFields as $field) {
26
                $columns[] = "(SELECT t.value FROM [$this->translateModel] AS t WHERE t.foreign_id = p.id AND t.lang = '$lang' AND t.key = '$field') AS $field";
27
            }
28
29
            $qb = $this->modelsManager->createBuilder()
0 ignored issues
show
Bug introduced by
The property modelsManager does not seem to exist. Did you mean _modelsManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
30
                ->columns($columns)
31
                ->addFrom('Page\Model\Page', 'p')
32
                ->where('p.slug = :slug:', ['slug' => $slug]);
33
34
            $result = $qb->getQuery()->execute()->getFirst();
35
            return $result;
36
37
        }, $lifeTime);
38
39
        return $pageResult;
40
    }
41
42
}