Completed
Push — develop ( 4ff741...64bd10 )
by Tom
14:53
created

ClassifyResponse::getImages()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 5
eloc 14
nc 2
nop 0
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Classifier;
6
use Bobbyshaw\WatsonVisualRecognition\Image;
7
8
/**
9
 * Class ClassifyResponse
10
 * @package Bobbyshaw\WatsonVisualRecognition\Message
11
 */
12
class ClassifyResponse extends Response
13
{
14
    /**
15
     * Images in the response
16
     *
17
     * @var Image[]
18
     */
19
    protected $images;
20
21
    /**
22
     * Get Images
23
     *
24
     * @return Image[]
25
     */
26
    public function getImages()
27
    {
28
        if (!$this->images) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->images of type Bobbyshaw\WatsonVisualRecognition\Image[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
29
            $images = [];
30
            foreach ($this->data->images as $image) {
31
                $classifiers = [];
32
                if (isset($image->scores)) {
33
                    foreach ($image->scores as $classifier) {
34
                        $classifiers[] = new Classifier(
35
                            $classifier->classifier_id,
36
                            $classifier->name,
37
                            $classifier->score
38
                        );
39
                    }
40
                }
41
                $images[] = new Image($image->image, $classifiers);
42
            }
43
            $this->images = $images;
44
        }
45
46
        return $this->images;
47
    }
48
}
49