Completed
Pull Request — master (#4)
by Laurens
04:30 queued 01:41
created

BaseReport::getReportLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Werkspot\BingAdsApiBundle\Api\Report;
3
4
use BingAds\Reporting\ReportRequest;
5
6
class BaseReport implements ReportInterface
7
{
8
    const WSDL = 'https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl';
9
    const FILE_HEADERS = 10;
10
    const COLUMN_HEADERS = 1;
11
12
    protected $reportRequest;
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function __construct()
18
    {
19
        $this->createReportRequest();
20
    }
21
22
    /**
23
     * @param $format
24
     *
25
     * @return $this
26
     */
27
    public function setFormat($format)
28
    {
29
        $this->reportRequest->Format = $format;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param bool $returnOnlyCompleteData
36
     *
37
     * @return $this
38
     */
39
    public function setReturnOnlyCompleteData($returnOnlyCompleteData)
40
    {
41
        $this->reportRequest->ReturnOnlyCompleteData = $returnOnlyCompleteData;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param string $language
48
     *
49
     * @return $this
50
     */
51
    public function setReportLanguage($language)
52
    {
53
        $this->reportRequest->Language = $language;
1 ignored issue
show
Documentation Bug introduced by
It seems like $language of type string is incompatible with the declared type object<BingAds\Reporting\ReportLanguage> of property $Language.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
55
        return $this;
56
    }
57
58
    protected function createReportRequest()
59
    {
60
        $this->reportRequest = new ReportRequest();
61
    }
62
63
    /**
64
     * @param array|null $columns
65
     * @param string|null $timePeriod (See BingAds SDK documentation)
66
     *
67
     * @return ReportRequest
68
     */
69
    public function getRequest(array $columns = null, $timePeriod = null)
70
    {
71
        return $this->reportRequest;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->reportRequest; (BingAds\Reporting\ReportRequest) is incompatible with the return type declared by the interface Werkspot\BingAdsApiBundl...rtInterface::getRequest of type Werkspot\BingAdsApiBundle\Api\Report\ReportRequest.

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...
72
    }
73
}
74