Completed
Push — master ( b70c79...5b2de4 )
by
unknown
04:34
created

Theme::templateSelector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPFoundation\Configuration\Theme;
13
14
use LIN3S\WPFoundation\Configuration\Acf\Wysiwyg;
15
16
/**
17
 * Abstract class of theme that implements the interface.
18
 * This class avoids the use of callbacks in the constructor.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
abstract class Theme implements ThemeInterface
23
{
24
    /**
25
     * Constructor.
26
     */
27
    public function __construct()
28
    {
29
        $this->acf();
30
        $this->classes();
31
        $this->templateSelector();
0 ignored issues
show
Unused Code introduced by
The call to the method LIN3S\WPFoundation\Confi...eme::templateSelector() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
32
        add_theme_support('post-thumbnails');
0 ignored issues
show
Unused Code introduced by
The call to the function add_theme_support() seems unnecessary as the function has no side-effects.
Loading history...
33
        add_filter('timber_context', [$this, 'context']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
34
    }
35
36
    /**
37
     * All about ACF configuration should be instantiated here.
38
     */
39
    protected function acf()
40
    {
41
        new Wysiwyg([
42
            'lin3s' => [1 => ['bold', 'italic', 'bullist', 'numlist', 'link', 'unlink']],
43
        ]);
44
    }
45
46
    /**
47
     * Filters the selectable templates.
48
     */
49
    private function templateSelector()
50
    {
51
        $self = $this;
52
        add_filter('theme_page_templates', function() use ($self) {
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
53
            return $self->templates([]);
54
        });
55
    }
56
}
57