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

Fields   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 8
Bugs 4 Features 3
Metric Value
wmc 9
c 8
b 4
f 3
lcom 1
cbo 0
dl 0
loc 60
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A fields() 0 12 4
A components() 0 4 1
A addScreenAttributes() 0 3 1
A removeScreenAttributes() 0 3 1
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