1 | <?php |
||
11 | class SearchConsole |
||
12 | { |
||
13 | /** @var SearchConsoleClient */ |
||
14 | protected $client; |
||
15 | |||
16 | /** |
||
17 | * @param SearchConsoleClient $client |
||
18 | */ |
||
19 | public function __construct(SearchConsoleClient $client) |
||
23 | |||
24 | /** |
||
25 | * @param string $quotaUser |
||
26 | * |
||
27 | * @return $this |
||
28 | */ |
||
29 | public function setQuotaUser(string $quotaUser) |
||
35 | |||
36 | /** |
||
37 | * @param string $accessToken |
||
38 | * |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function setAccessToken(string $accessToken) |
||
47 | |||
48 | public function getSite(string $siteUrl) |
||
61 | |||
62 | public function listSites() |
||
78 | |||
79 | /** |
||
80 | * Call the query method on the authenticated client. |
||
81 | * |
||
82 | * @param Period $period |
||
83 | * @param array $dimensions |
||
84 | * @param array $filters |
||
85 | * @param int $rows |
||
86 | * @param string $searchType |
||
87 | * @return Collection |
||
88 | */ |
||
89 | public function searchAnalyticsQuery(string $siteUrl, Period $period, array $dimensions = [], array $filters = [], int $rows = 1000, string $searchType = 'web') |
||
100 | |||
101 | /* |
||
102 | * Get the underlying Google_Service_Webmasters object. You can use this |
||
103 | * to basically call anything on the Google Search Console API. |
||
104 | */ |
||
105 | public function getWebmastersService(): \Google_Service_Webmasters |
||
109 | |||
110 | private function applyFilters(Google_Service_Webmasters_SearchAnalyticsQueryRequest $request, $filters) |
||
132 | |||
133 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: