ObjectToItem::get_category()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 15
cp 0
rs 9.2
cc 4
eloc 7
nc 3
nop 0
crap 20
1
<?php
2
3
/**
4
 *
5
 */
6
7
namespace ApaiIO\ResponseTransformer;
8
9
/**
10
 *
11
 */
12
class ObjectToItem extends ObjectToArray implements ResponseTransformerInterface {
13
14
    /**
15
     *
16
     * @var type
17
     */
18
    protected $data = array();
19
20
    /**
21
     *
22
     * @var type
23
     */
24
    protected $item = array();
25
26
    /**
27
     *
28
     * @param type $response
29
     * @return type
30
     */
31
    public function transform($response)
32
    {
33
        $response = parent::transform($response);
34
35
        if( !$this->get_item( $response ) )
36
        {
37
            return array();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(); (array) is incompatible with the return type documented by ApaiIO\ResponseTransformer\ObjectToItem::transform of type ApaiIO\ResponseTransformer\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
38
        }
39
40
        $this->set( 'asin', 'ASIN' );
0 ignored issues
show
Documentation introduced by
'asin' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ASIN' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        $this->set( 'title', 'ItemAttributes', 'Title' );
0 ignored issues
show
Documentation introduced by
'title' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Title' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
        $this->set( 'manufacturer', 'ItemAttributes', 'Manufacturer' );
0 ignored issues
show
Documentation introduced by
'manufacturer' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Manufacturer' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
        $this->set( 'isbn', 'ItemAttributes', 'ISBN' );
0 ignored issues
show
Documentation introduced by
'isbn' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ISBN' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
        $this->set( 'publisher', 'ItemAttributes', 'Publisher' );
0 ignored issues
show
Documentation introduced by
'publisher' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Publisher' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        $this->set( 'number_of_pages', 'ItemAttributes', 'NumberOfPages' );
0 ignored issues
show
Documentation introduced by
'number_of_pages' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'NumberOfPages' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        $this->set( 'number_of_items', 'ItemAttributes', 'NumberOfItems' );
0 ignored issues
show
Documentation introduced by
'number_of_items' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'NumberOfItems' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $this->set( 'number_of_issues', 'ItemAttributes', 'NumberOfIssues' );
0 ignored issues
show
Documentation introduced by
'number_of_issues' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'NumberOfIssues' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
        $this->set( 'model', 'ItemAttributes', 'Model' );
0 ignored issues
show
Documentation introduced by
'model' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Model' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
        $this->set( 'label', 'ItemAttributes', 'Label' );
0 ignored issues
show
Documentation introduced by
'label' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Label' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        $this->set( 'format', 'ItemAttributes', 'Format' );
0 ignored issues
show
Documentation introduced by
'format' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Format' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
        $this->set( 'edition', 'ItemAttributes', 'Edition' );
0 ignored issues
show
Documentation introduced by
'edition' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Edition' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        $this->set( 'artist', 'ItemAttributes', 'Artist' );
0 ignored issues
show
Documentation introduced by
'artist' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'ItemAttributes' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Artist' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
        $this->set( 'description', 'EditorialReviews', 'EditorialReview', 'Content' );
0 ignored issues
show
Documentation introduced by
'description' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReviews' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReview' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Content' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
        $this->set( 'lowest_new_price', 'OfferSummary', 'LowestNewPrice', 'Amount' );
0 ignored issues
show
Documentation introduced by
'lowest_new_price' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'OfferSummary' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'LowestNewPrice' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Amount' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $this->set( 'large_image', 'LargeImage', 'URL' );
0 ignored issues
show
Documentation introduced by
'large_image' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'LargeImage' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'URL' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        $this->set( 'medium_image', 'MediumImage', 'URL' );
0 ignored issues
show
Documentation introduced by
'medium_image' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'MediumImage' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'URL' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        $this->set( 'small_image', 'SmallImage', 'URL' );
0 ignored issues
show
Documentation introduced by
'small_image' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'SmallImage' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'URL' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
        $this->set_array( 'author', 'ItemAttributes', 'Author' );
59
        $this->set_array( 'features', 'ItemAttributes', 'Feature' );
60
61
        $this->get_reviews();
62
        $this->get_price();
63
        $this->get_description();
64
        $this->get_category();
65
        $this->get_image_sets();
66
67
        return $this->data;
68
    }
69
70
    /**
71
     *
72
     * @param type $response
73
     * @return mixed
74
     */
75
    protected function get_item($response)
76
    {
77
        if( isset( $response['Items']['Item'] ) AND is_array( $response['Items']['Item'] ) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
78
        {
79
            if( array_key_exists( 1, $response['Items']['Item'] ) )
80
            {
81
                return $this->item = $response['Items']['Item'][0];
82
            }
83
            else
84
            {
85
                return $this->item = $response['Items']['Item'];
86
            }
87
        }
88
        else
89
        {
90
            return FALSE;
91
        }
92
    }
93
94
    /**
95
     *
96
     * @param type $data
97
     * @param type $key1
98
     * @param type $key2
99
     * @param type $key3
100
     */
101
    protected function set($data, $key1, $key2 = NULL, $key3 = NULL, $key4 = NULL)
102
    {
103
        if( $key4 )
104
        {
105 View Code Duplication
            if( isset( $this->item[$key1][$key2][$key3][$key4] ) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
            {
107
                $this->data[$data] = $this->item[$key1][$key2][$key3][$key4];
108
            }
109
        }
110 View Code Duplication
        elseif( $key3 )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
        {
112
            if( isset( $this->item[$key1][$key2][$key3] ) )
113
            {
114
                $this->data[$data] = $this->item[$key1][$key2][$key3];
115
            }
116
        }
117
        elseif( $key2 )
118
        {
119
            if( isset( $this->item[$key1][$key2] ) )
120
            {
121
                $this->data[$data] = $this->item[$key1][$key2];
122
            }
123
        }
124
        else
125
        {
126
            if( isset( $this->item[$key1] ) )
127
            {
128
                $this->data[$data] = $this->item[$key1];
129
            }
130
        }
131
    }
132
133
    protected function set_array($data, $key1, $key2 = NULL, $key3 = NULL)
134
    {
135
        $this->set( $data, $key1, $key2, $key3 );
136
        if( isset( $this->data[$data] ) AND !is_array( $this->data[$data] ) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
137
        {
138
            $this->data[$data] = array($this->data[$data]);
139
        }
140
    }
141
142
    private function get_price()
143
    {
144
        $list_price = isset( $this->item['ItemAttributes']['ListPrice']['Amount'] ) ? $this->item['ItemAttributes']['ListPrice']['Amount'] : NULL;
145
        $amazon_price = isset( $this->item['Offers']['Offer']['OfferListing']['Price']['Amount'] ) ? $this->item['Offers']['Offer']['OfferListing']['Price']['Amount'] : NULL;
146
        $saved = isset( $this->item['Offers']['Offer']['OfferListing']['AmountSaved'] ) ? $this->item['Offers']['Offer']['OfferListing']['AmountSaved']['Amount'] : NULL;
147
        $price = ($list_price) ? $list_price : ($amazon_price ? ($amazon_price + $saved) : NULL );
148
        $this->data['price'] = ($price) ? $price : (isset($this->data['lowest_new_price']) ? $this->data['lowest_new_price'] : 0);
149
    }
150
151
    private function get_description()
152
    {
153
        if(isset( $this->item['EditorialReviews']['EditorialReview'][1] ) )
154
        {
155
            $this->set( 'description', 'EditorialReviews', 'EditorialReview', 0, 'Content' );
0 ignored issues
show
Documentation introduced by
'description' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReviews' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReview' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
0 is of type integer, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
156
        }
157
        else
158
        {
159
            $this->set( 'description', 'EditorialReviews', 'EditorialReview', 'Content' );
0 ignored issues
show
Documentation introduced by
'description' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReviews' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'EditorialReview' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Content' is of type string, but the function expects a object<ApaiIO\ResponseTransformer\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
160
        }
161
        if( isset( $this->data['description'] ) )
162
        {
163
            $this->data['description'] = $this->html2txt( $this->data['description'] );
164
        }
165
    }
166
167
    /**
168
     * Parses the Amazon reviews iframe to get precise numeric review metrics
169
     */
170
    private function get_reviews()
171
    {
172
        if( isset( $this->item['CustomerReviews']['IFrameURL'] ) )
173
        {
174
            // Load the iFrame HTML from the URL returned by the API
175
            $text = file_get_contents( $this->item['CustomerReviews']['IFrameURL'] );
176
177
            // Clean up the HTML removing scripts and other unneeded data
178
            $text = preg_replace( '/(<style>.+?)+(<\/style>)/i', '', $text );
179
            $search = array('@<script[^>]*?>.*?</script>@si',  // javascript
180
                            '@<style[^>]*?>.*?</style>@siU',   // style tags properly
181
                            '@<![\s\S]*?--[ \t\n\r]*>@',       // multi-line comments including CDATA
182
                            '/^\n+|^[\t\s]*\n+/m',             // empty lines
183
            );
184
            $text = trim( preg_replace( $search, '', $text ) );
185
186
            // Load HTML into SimpleXML for parsing
187
            libxml_use_internal_errors( TRUE );
188
            $dom = new \DOMDocument();
189
            $dom->strictErrorChecking = FALSE;
190
            $dom->recover = TRUE;
191
            $dom->loadHTML( $text );
192
            $xml = simplexml_import_dom( $dom );
193
194
            // Get the total amount of reviews
195
            $stars = $xml->xpath( "//span[@class='crAvgStars']" );
196
            $total_reviews = isset( $stars[0] ) ? (int)preg_replace( '/[^\d]/', '', $stars[0]->a ) : 0;
197
198
            // Get the average rating
199
            $summary = $xml->xpath( "//span[@class='asinReviewsSummary']" );
200
            if( isset($summary[0]) )
201
            {
202
                $img = $summary[0]->xpath('a/img');
203
                $summary = preg_replace( '/[^\d]/', '', (string)$img[0]->attributes()->alt );
204
                $summary = (float)((int)substr( $summary, 0, strlen($summary)-1 ))/10;
205
            }
206
            else
207
            {
208
                $summary = 0;
209
            }
210
211
            // Set data in response
212
            $this->data['reviews'] = array(
213
                'total' => $total_reviews,
214
                'average' => $summary,
215
            );
216
        }
217
    }
218
219
    /**
220
     *
221
     */
222
    private function get_image_sets()
223
    {
224
        if( isset( $this->item['ImageSets']['ImageSet'] ) AND is_array( $this->item['ImageSets']['ImageSet'] ) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
225
        {
226
            $this->data['image_sets'] = array();
227
228
            $sets = $this->item['ImageSets'];
229
230 View Code Duplication
            foreach( $sets as $set )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
231
            {
232
                $row = array();
233
                if( isset( $set['MediumImage']['URL'] ) )
234
                {
235
                    $row['medium_image'] = $set['MediumImage']['URL'];
236
                }
237
                if( isset( $set['LargeImage']['URL'] ) )
238
                {
239
                    $row['large_image'] = $set['LargeImage']['URL'];
240
                }
241
                $this->data['image_sets'][] = $row;
242
            }
243
        }
244
    }
245
246
    private function get_category()
247
    {
248
        if( isset( $this->item['BrowseNodes']['BrowseNode'] ) AND is_array( $this->item['BrowseNodes']['BrowseNode'] ) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
249
        {
250
            if( isset( $this->item['BrowseNodes']['BrowseNode'][0] ) )
251
            {
252
                $node = $this->item['BrowseNodes']['BrowseNode'][0];
253
            }
254
            else
255
            {
256
                $node = $this->item['BrowseNodes']['BrowseNode'];
257
            }
258
            $this->data['category'] = $this->get_ancestor( $node );
259
        }
260
    }
261
262 View Code Duplication
    private function get_ancestor($node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
    {
264
        if( isset( $node['Ancestors'] ) AND is_array( $node['Ancestors'] ) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
265
        {
266
            return $this->get_ancestor( $node['Ancestors']['BrowseNode'] );
267
        }
268
        else
269
        {
270
            return isset( $node['Name'] ) ? $node['Name'] : 'Uncategorized';
271
        }
272
    }
273
274
}
275