Completed
Push — develop ( c635bd...85470e )
by
unknown
09:19 queued 10s
created

Status   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 78
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getName() 0 4 1
A getOrder() 0 4 1
A __toString() 0 4 1
A getStates() 0 11 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Cv\Entity;
11
12
use Core\Entity\AbstractEntity;
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
15
/**
16
 * @ODM\EmbeddedDocument
17
 */
18
class Status extends AbstractEntity implements StatusInterface
19
{
20
    /**
21
     * status values
22
     */
23
    protected static $orderMap = [
24
        self::NONPUBLIC => 10,
25
        self::PUBLIC_TO_ALL => 20
26
    ];
27
28
    /**
29
     * name of the status
30
     *
31
     * @var string
32
     * @ODM\Field(type="string")
33
     */
34
    protected $name;
35
36
    /**
37
     * integer for ordering states.
38
     *
39
     * @var string
40
     * @ODM\Field(type="string")
41
     */
42
    protected $order;
43
44
    /**
45
     * @see \Cv\Entity\StatusInterface::__construct()
46
     */
47
    public function __construct($status = self::NONPUBLIC)
48
    {
49
        if (!isset(static::$orderMap[$status])) {
50
            throw new \DomainException('Unknown status: ' . $status);
51
        }
52
        
53
        $this->name = $status;
54
        $this->order = $this->getOrder();
55
    }
56
57
    /**
58
     * @see \Cv\Entity\StatusInterface::getName()
59
     */
60
    public function getName()
61
    {
62
        return $this->name;
63
    }
64
65
    /**
66
     * @see \Cv\Entity\StatusInterface::getOrder()
67
     */
68
    public function getOrder()
69
    {
70
        return self::$orderMap[$this->getName()];
71
    }
72
73
    /**
74
     * @see \Cv\Entity\StatusInterface::__toString()
75
     */
76
    public function __toString()
77
    {
78
        return $this->getName();
79
    }
80
81
    /**
82
     * @see \Cv\Entity\StatusInterface::getStates()
83
     */
84
    public function getStates(array $exclude = [])
85
    {
86
        $states = self::$orderMap;
87
        
88
        if ($exclude) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $exclude of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
89
            $states = array_diff_key($states, array_flip($exclude));
90
        }
91
        
92
        asort($states, SORT_NUMERIC);
93
        return array_keys($states);
94
    }
95
}
96