Completed
Push — master ( 3ecbe1...f7c2f1 )
by Jan
04:05
created

Part::getAmountSum()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 6
nop 0
dl 0
loc 18
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
declare(strict_types=1);
33
34
/**
35
 * part-db version 0.1
36
 * Copyright (C) 2005 Christoph Lechner
37
 * http://www.cl-projects.de/.
38
 *
39
 * part-db version 0.2+
40
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
41
 * http://code.google.com/p/part-db/
42
 *
43
 * Part-DB Version 0.4+
44
 * Copyright (C) 2016 - 2019 Jan Böhmer
45
 * https://github.com/jbtronics
46
 *
47
 * This program is free software; you can redistribute it and/or
48
 * modify it under the terms of the GNU General Public License
49
 * as published by the Free Software Foundation; either version 2
50
 * of the License, or (at your option) any later version.
51
 *
52
 * This program is distributed in the hope that it will be useful,
53
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55
 * GNU General Public License for more details.
56
 *
57
 * You should have received a copy of the GNU General Public License
58
 * along with this program; if not, write to the Free Software
59
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
60
 */
61
62
namespace App\Entity\Parts;
63
64
use App\Entity\Attachments\Attachment;
65
use App\Entity\Attachments\AttachmentContainingDBElement;
66
use App\Entity\Devices\Device;
67
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
68
use App\Entity\Parts\PartTraits\MasterAttachmentTrait;
69
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
70
use App\Entity\Parts\PartTraits\InstockTrait;
71
use App\Entity\Parts\PartTraits\ManufacturerTrait;
72
use App\Entity\Parts\PartTraits\OrderTrait;
73
use App\Entity\PriceInformations\Orderdetail;
74
use App\Security\Annotations\ColumnSecurity;
75
use App\Validator\Constraints\Selectable;
76
use Doctrine\Common\Collections\ArrayCollection;
77
use Doctrine\Common\Collections\Collection;
78
use Doctrine\ORM\Mapping as ORM;
79
80
use Symfony\Component\Validator\Constraints as Assert;
81
82
/**
83
 * Part class.
84
 *
85
 * DONT USE orphanRemoval on properties with ColumnSecurity!! An empty collection will be created as placeholder,
86
 * and the partlots are deleted, even if we want dont want that!
87
 *
88
 * The class properties are split over various traits in directory PartTraits.
89
 * Otherwise this class would be too big, to be maintained.
90
 *
91
 * @ORM\Entity(repositoryClass="App\Repository\PartRepository")
92
 * @ORM\Table("`parts`")
93
 */
94
class Part extends AttachmentContainingDBElement
95
{
96
    use AdvancedPropertyTrait;
97
    use MasterAttachmentTrait;
98
    use BasicPropertyTrait;
99
    use InstockTrait;
100
    use ManufacturerTrait;
101
    use OrderTrait;
102
103
    //TODO
104
    protected $devices;
105
106
    /**
107
     * @ColumnSecurity(type="datetime")
108
     * @ORM\Column(type="datetime", name="datetime_added", options={"default"="CURRENT_TIMESTAMP"})
109
     */
110
    protected $addedDate;
111
112
    /**
113
     * @var \DateTime The date when this element was modified the last time.
114
     * @ColumnSecurity(type="datetime")
115
     * @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"})
116
     */
117
    protected $lastModified;
118
119
    /**
120
     * @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=false)
121
     * @ColumnSecurity(type="collection", prefix="attachments")
122
     * @Assert\Valid()
123
     */
124
    protected $attachments;
125
126
    public function __construct()
127
    {
128
        parent::__construct();
129
        $this->partLots = new ArrayCollection();
130
        $this->orderdetails = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type App\Entity\PriceInformations\Orderdetail[] of property $orderdetails.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
131
    }
132
133
    /**
134
     * Returns the ID as an string, defined by the element class.
135
     * This should have a form like P000014, for a part with ID 14.
136
     *
137
     * @return string The ID as a string;
138
     */
139
    public function getIDString(): string
140
    {
141
        return 'P' . sprintf('%06d', $this->getID());
142
    }
143
144
    /**
145
     *  Get all devices which uses this part.
146
     *
147
     * @return Device[] * all devices which uses this part as a one-dimensional array of Device objects
148
     *                  (empty array if there are no ones)
149
     *                  * the array is sorted by the devices names
150
     *
151
     */
152
    public function getDevices(): array
153
    {
154
        return $this->devices;
155
    }
156
157
}
158