DMSRequestItem::getDocument()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Class DMSRequestItem wrapper which represents a DocumentCartItem
5
 */
6
class DMSRequestItem extends ViewableData
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * The number of copies required of @itemID
10
     *
11
     * @var int
12
     */
13
    private $quantity;
14
15
    /**
16
     * The linked {@link DMSDocument} which was added to the cart.
17
     *
18
     * @var DMSDocument
19
     */
20
    private $document;
21
22
    /**
23
     * If a document is provided on construction, set it to this item instance
24
     *
25
     * @param DMSDocument $document
0 ignored issues
show
Documentation introduced by
Should the type for parameter $document not be DMSDocument|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
26
     */
27
    public function __construct($document = null)
28
    {
29
        if ($document instanceof DMSDocument) {
30
            $this->setDocument($document);
31
        }
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Returns the ID of the $this->document
37
     *
38
     * @return int
39
     */
40
    public function getItemId()
41
    {
42
        return $this->document->ID;
43
    }
44
45
    /**
46
     * Returns the linked item Quantity
47
     *
48
     * @return int
49
     */
50
    public function getQuantity()
51
    {
52
        return $this->quantity;
53
    }
54
55
    /**
56
     * Sets the quantity of documents to be ordered.
57
     *
58
     * @param int $quantity
59
     *
60
     * @return DMSRequestItem
61
     */
62
    public function setQuantity($quantity)
63
    {
64
        $this->quantity = (int) $quantity;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Returns the linked DMSDocument
71
     *
72
     * @return DMSDocument
0 ignored issues
show
Documentation introduced by
Should the return type not be DMSDocument|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
73
     */
74
    public function getDocument()
75
    {
76
        if ($this->document) {
77
            return DMSDocument::get()->byID($this->document->ID);
78
        }
79
    }
80
81
    /**
82
     * @param DMSDocument $document
83
     *
84
     * @return DMSRequestItem
85
     */
86
    public function setDocument($document)
87
    {
88
        $this->document = $document;
89
90
        return $this;
91
    }
92
}
93