Completed
Push — master ( 5c637a...214bce )
by Julien
03:47
created

MoviesItem::getMovie()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6667
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Cart;
4
use App\Http\Cart\Exception\ItemException;
5
use App\Http\Models\Movies;
6
7
/**
8
 * Interface ItemInterface
9
 * @package App\Http\Cart
10
 */
11
class MoviesItem implements ItemInterface{
12
13
    /**
14
     * @var $id
15
     */
16
    protected $id;
17
18
    /**
19
     * Constructor
20
     * @param $id
21
     */
22
    public function __construct($id){
23
24
        $this->id = $id;
25
    }
26
27
    /**
28
     * @return mixed
29
     */
30
    public function add(ItemInterface $item){}
31
32
    /**
33
     * @return mixed
34
     */
35
    public function remove(ItemInterface $item){}
36
37
    /**
38
     * @return mixed
39
     */
40
    public function clear(){}
41
42
    /**
43
     * @return mixed
44
     */
45
    public function all(){}
46
47
48
    /**
49
     * @param $id
50
     * @return mixed
51
     * @throws ItemException
52
     */
53
    public function getMovie(){
54
        $movie = Movies::find($this->id);
55
56
        if($movie->price !== 0){
57
            throw new ItemException('Le produit a un prix à 0');
58
        }
59
60
        return $movie;
61
    }
62
63
64
    /**
65
     * @return mixed
66
     * @throws ItemException
67
     */
68
    public function __toString(){
69
        return $this->getMovie()->id;
70
    }
71
72
}
73
74