Completed
Push — master ( a2a0a6...89c3f6 )
by Beñat
02:45
created

Fields::addScreenAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 1
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\PostTypes\Fields;
13
14
use LIN3S\WPFoundation\PostTypes\Fields\Components\FieldComponent;
15
16
/**
17
 * Abstract class of base custom fields that implements the interface.
18
 * This class avoids the redundant task of create the same Fields constructor.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
abstract class Fields implements FieldsInterface
23
{
24
    /**
25
     * The template name.
26
     *
27
     * @var string
28
     */
29
    protected $name;
30
31
    /**
32
     * Constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->fields();
37
        $this->connector();
38
39
        if (false === is_admin()) {
40
            return;
41
        }
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function fields()
48
    {
49
        foreach ($this->components() as $component) {
50
            if (false === class_exists($component)) {
51
                throw new \Exception(sprintf('The %s class does not exist', $component));
52
            }
53
            if ($component instanceof FieldComponent) {
54
                throw new \Exception('The %s class must be extend the FieldComponent', $component);
55
            }
56
            $component::register($this->name, $this->connector());
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function components()
64
    {
65
        return [];
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function addScreenAttributes()
72
    {
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function removeScreenAttributes()
79
    {
80
    }
81
}
82