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

ClassifyResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getImages() 0 22 5
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