Passed
Pull Request — master (#158)
by Robbie
01:53 queued 20s
created

ElementalPageExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 51
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A MetaTags() 0 13 3
A getElementsForSearch() 0 15 4
1
<?php
2
3
namespace DNADesign\Elemental\Extensions;
4
5
use DNADesign\Elemental\Models\ElementalArea;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\View\Parsers\HTML4Value;
9
10
class ElementalPageExtension extends ElementalAreasExtension
11
{
12
    /**
13
     * @var array
14
     */
15
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
16
        'ElementalArea' => ElementalArea::class
17
    ];
18
19
    /**
20
     * @var array
21
     */
22
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
23
        'ElementalArea'
24
    ];
25
26
    /**
27
     * Returns the contents of each ElementalArea has_one's markup for use in Solr search indexing
28
     *
29
     * @return string
30
     */
31
    public function getElementsForSearch()
32
    {
33
        $output = [];
34
        foreach ($this->owner->hasOne() as $key => $class) {
35
            if ($class !== ElementalArea::class) {
36
                continue;
37
            }
38
39
            /** @var ElementalArea $area */
40
            $area = $this->owner->$key();
41
            if ($area) {
42
                $output[] = strip_tags($area->forTemplate());
43
            }
44
        }
45
        return implode($output);
0 ignored issues
show
Bug introduced by
$output of type array|string[] is incompatible with the type string expected by parameter $glue of implode(). ( Ignorable by Annotation )

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

45
        return implode(/** @scrutinizer ignore-type */ $output);
Loading history...
Bug introduced by
The call to implode() has too few arguments starting with pieces. ( Ignorable by Annotation )

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

45
        return /** @scrutinizer ignore-call */ implode($output);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
46
    }
47
48
    public function MetaTags(&$tags)
49
    {
50
        $controller = Controller::curr();
51
        $request = $controller->getRequest();
52
        if ($request->getVar('ElementalPreview') !== null) {
53
            $html = HTML4Value::create($tags);
54
            $xpath = "//meta[@name='x-page-id' or @name='x-cms-edit-link']";
55
            $removeTags = $html->query($xpath);
56
            $body = $html->getBody();
57
            foreach ($removeTags as $tag) {
58
                $body->removeChild($tag);
59
            }
60
            $tags = $html->getContent();
61
        }
62
    }
63
}
64