Passed
Branch release/1.5.0 (d52397)
by vincent
02:35
created

Collection::getPosters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
namespace vfalies\tmdb\Items;
4
5
use vfalies\tmdb\Abstracts\Item;
6
use vfalies\tmdb\Interfaces\Items\CollectionInterface;
7
use vfalies\tmdb\Tmdb;
8
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
9
use vfalies\tmdb\Exceptions\NotFoundException;
10
use vfalies\tmdb\Traits\ElementTrait;
11
use vfalies\tmdb\Results\Movie;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, vfalies\tmdb\Items\Movie.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use vfalies\tmdb\Results\Image;
13
14
class Collection extends Item implements CollectionInterface
15
{
16
17
    use ElementTrait;
18
19
    // Private loaded data
20
    protected $data = null;
21
    protected $conf = null;
22
    protected $id   = null;
23
    protected $tmdb = null;
24
25
    /**
26
     * Constructor
27
     * @param Tmdb $tmdb
28
     * @param int $collection_id
29
     * @param array $options
30
     */
31 19
    public function __construct(Tmdb $tmdb, $collection_id, array $options = array())
32
    {
33 19
        parent::__construct($tmdb, $collection_id, $options, 'collection');
34 18
    }
35
36
    /**
37
     * Get collection ID
38
     * @return int
39
     */
40 2
    public function getId()
41
    {
42 2
        return $this->id;
43
    }
44
45
    /**
46
     * Get collection name
47
     * @return string
48
     * @throws NotFoundException
49
     */
50 2
    public function getName()
51
    {
52 2
        if (isset($this->data->name)) {
53 1
            return $this->data->name;
54
        }
55 1
        $this->logger->error('Collection name not found', array('collection_id' => $this->id));
56 1
        throw new NotFoundException;
57
    }
58
59
    /**
60
     * Get collection parts
61
     * @return Generator
62
     */
63 2
    public function getParts()
64
    {
65 2
        if (!empty($this->data->parts)) {
66 1
            foreach ($this->data->parts as $part) {
67 1
                $movie = new Movie($this->tmdb, $part);
68 1
                yield $movie;
69
            }
70
        }
71 2
    }
72
73 9
    public function getBackdrops()
74
    {
75 9
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/collection/'.(int) $this->id.'/images', null, $this->params);
76
77 9
        foreach ($data->backdrops as $b)
78
        {
79 9
            $image = new Image($this->tmdb, $this->id, $b);
80 9
            yield $image;
81
        }
82 1
    }
83
84 1
    public function getPosters()
85
    {
86 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/collection/'.(int) $this->id.'/images', null, $this->params);
87
88 1
        foreach ($data->posters as $b)
89
        {
90 1
            $image = new Image($this->tmdb, $this->id, $b);
91 1
            yield $image;
92
        }
93 1
    }
94
}
95