Completed
Push — develop ( 168e99...0122be )
by
unknown
18:37 queued 07:11
created

OrderNumberCounter::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Orders\Entity;
12
13
use Core\Entity\EntityInterface;
14
use Core\Entity\EntityTrait;
15
use Core\Entity\IdentifiableEntityInterface;
16
use Core\Entity\IdentifiableEntityTrait;
17
use Core\Entity\ImmutableEntityInterface;
18
use Core\Entity\ImmutableEntityTrait;
19
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
20
21
/**
22
 * ${CARET}
23
 *
24
 * @ODM\Document(collection="orders.ordernumbercounter")
25
 * @ODM\UniqueIndex(keys={"name", "count"})
26
 * @author Mathias Gelhausen <[email protected]>
27
 * @todo write test 
28
 */
29
class OrderNumberCounter implements EntityInterface, IdentifiableEntityInterface, ImmutableEntityInterface
30
{
31
    use EntityTrait, IdentifiableEntityTrait, ImmutableEntityTrait;
32
33
    /**
34
     * The name of this counter. used as Prefix for the number.
35
     *
36
     * @ODM\String
37
     * @var string
38
     */
39
    protected $name;
40
41
    /**
42
     * the next counter number to use.
43
     *
44
     * @ODM\Field(type="int")
45
     * @var int
46
     */
47
    protected $count = 0;
48
49
    /**
50
     * @param string $name
51
     *
52
     * @return self
53
     */
54
    public function setName($name)
55
    {
56
        $this->name = $name;
57
58
        return $this;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getName()
65
    {
66
        return $this->name;
67
    }
68
69
    /**
70
     * @param int $count
71
     *
72
     * @return self
73
     */
74
    public function setCount($count)
75
    {
76
        $this->count = $count;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function getCount()
85
    {
86
        return $this->count;
87
    }
88
89
    public function format($format = null)
90
    {
91
        if (null === $format) {
92
            $format = '%1$s-%2$s';
93
        }
94
95
        return sprintf($format, $this->getName(), $this->getCount());
96
    }
97
98
    public function __toString()
99
    {
100
        return $this->format();
101
    }
102
}