Item::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
ccs 7
cts 7
cp 1
crap 2
1
<?php
2
/**
3
 * @category    Brownie/CartsGuru
4
 * @author      Brownie <[email protected]>
5
 * @license     http://www.gnu.org/copyleft/lesser.html
6
 */
7
8
namespace Brownie\CartsGuru\Model;
9
10
use Brownie\CartsGuru\Model\Base\ArrayList;
11
use Brownie\CartsGuru\Exception\ValidateException;
12
13
/**
14
 * Item Model.
15
 *
16
 * @method  Item    setId($id)
17
 * @method  Item    setLabel($label)
18
 * @method  Item    setQuantity($quantity)
19
 * @method  Item    setTotalATI($totalATI)
20
 * @method  Item    setTotalET($totalET)
21
 * @method  Item    setUrl($url)
22
 * @method  Item    setImageUrl($imageUrl)
23
 * @method  Item    setUniverse($universe)
24
 * @method  Item    setCategory($category)
25
 */
26
class Item extends ArrayList
27
{
28
29
    protected $fields = array(
30
        'id' => null,               // SKU or product id
31
        'label' => null,            // Designation
32
        'quantity' => null,         // Count
33
        'totalATI' => null,         // Total price included taxes
34
        'totalET' => null,          // Total price excluded taxes
35
        'url' => null,              // URL of product sheet
36
        'imageUrl' => null,         // Image URL of the  product, size should be min 150*150, max 180*180
37
        'universe' => null,         // Main category of the product (optional)
38
        'category' => null,         // Sub category of the product (optional)
39
    );
40
41
    /**
42
     * Validates contact data.
43
     *
44
     * @throws ValidateException
45
     */
46 2
    public function validate()
47
    {
48 2
        $args = array_filter(parent::toArray());
49
50 2
        $keys = array_diff(array(
51 2
            'id',
52
            'label',
53
            'quantity',
54
            'totalATI',
55
            'totalET',
56
            'url',
57
            'imageUrl',
58 2
        ), array_keys($args));
59
60 2
        if (!empty($keys)) {
61 1
            throw new ValidateException('No required fields: ' . implode(', ', $keys));
62
        }
63 1
    }
64
}
65