Completed
Pull Request — develop (#542)
by Mathias
09:01
created

Status::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
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
/** StatusInterface.php */
11
    
12
namespace Jobs\Entity;
13
14
use Core\Entity\EntityTrait;
15
use Core\Entity\Status\AbstractSortableStatus;
16
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17
18
/**
19
 * Job status entity
20
 *
21
 * @ODM\EmbeddedDocument
22
 */
23
class Status extends AbstractSortableStatus implements StatusInterface
24
{
25
    use EntityTrait;
26
27
    /**
28
     * status values
29
     */
30
    protected static $sortMap = array(
31
        self::CREATED => 10,
32
        self::WAITING_FOR_APPROVAL => 20,
33
        self::REJECTED => 30,
34
        self::PUBLISH => 40,
35
        self::ACTIVE => 50,
36
        self::INACTIVE => 60,
37
        self::EXPIRED => 70,
38
    );
39
40
    /**
41
     * name of the job status
42
     *
43
     * @var string
44
     * @ODM\Field(type="string")
45
     * @deprecated since 0.29, replaced by AbstractStatus::$state
46
     */
47
    protected $name;
48
49
    /**
50
     * integer for ordering states.
51
     *
52
     * @var int
53
     * @ODM\Field(type="int")
54
     * @deprecated since 0.29, replaced by AbstractSortableStatus::$sort
55
     */
56
    protected $order;
57
58 10
    public function __construct($status = self::CREATED)
59
    {
60 10
        parent::__construct($status);
61
62 10
        $constant = 'self::' . strtoupper(str_replace(' ', '_', $status));
63 10
        if (!defined($constant)) {
64
            throw new \DomainException('Unknown status: ' . $status);
65
        }
66 10
        $this->name=constant($constant);
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Status::$name has been deprecated: since 0.29, replaced by AbstractStatus::$state ( Ignorable by Annotation )

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

66
        /** @scrutinizer ignore-deprecated */ $this->name=constant($constant);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
67 10
        $this->order=$this->getOrder();
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Status::$order has been deprecated: since 0.29, replaced by AbstractSortableStatus::$sort ( Ignorable by Annotation )

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

67
        /** @scrutinizer ignore-deprecated */ $this->order=$this->getOrder();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Jobs\Entity\Status::getOrder() has been deprecated: since 0,29, no replacement. ( Ignorable by Annotation )

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

67
        $this->order=/** @scrutinizer ignore-deprecated */ $this->getOrder();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
68 10
    }
69
70
    /**
71
     * @see \Jobs\Entity\StatusInterface::getName()
72
     * @return String
73
     * @deprecated since 0,29, use __toString()
74
     */
75
    public function getName()
76
    {
77
        return isset($this->name)?$this->name:'';
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Status::$name has been deprecated: since 0.29, replaced by AbstractStatus::$state ( Ignorable by Annotation )

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

77
        return isset(/** @scrutinizer ignore-deprecated */ $this->name)?$this->name:'';

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
78
    }
79
80
    /**
81
     * @see \Jobs\Entity\StatusInterface::getOrder()
82
     * @return Int
83
     * @deprecated since 0,29, no replacement.
84
     */
85
    public function getOrder()
86
    {
87
        return self::$sortMap[$this->getName()];
0 ignored issues
show
Deprecated Code introduced by
The function Jobs\Entity\Status::getName() has been deprecated: since 0,29, use __toString() ( Ignorable by Annotation )

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

87
        return self::$sortMap[/** @scrutinizer ignore-deprecated */ $this->getName()];

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
88
    }
89
90
    /**
91
     * @todo remove this some versions after 0.29
92
     *
93
     * @return string
94
     */
95 1
    public function __toString()
96
    {
97 1
        if (!$this->state) {
98
            $this->state = $this->name;
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Status::$name has been deprecated: since 0.29, replaced by AbstractStatus::$state ( Ignorable by Annotation )

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

98
            $this->state = /** @scrutinizer ignore-deprecated */ $this->name;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
99
        }
100 1
        return parent::__toString();
101
    }
102
103
    /**
104
     * @todo remove this some versions after 0.29
105
     *
106
     * @param object|string $state
107
     *
108
     * @return bool
109
     */
110
    public function is($state)
111
    {
112
        if (!$this->state) {
113
            $this->state = $this->name;
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Status::$name has been deprecated: since 0.29, replaced by AbstractStatus::$state ( Ignorable by Annotation )

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

113
            $this->state = /** @scrutinizer ignore-deprecated */ $this->name;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
114
        }
115
116
        return parent::is($state);
117
    }
118
}
119