These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of EC-CUBE |
||
5 | * |
||
6 | * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.ec-cube.co.jp/ |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Helper; |
||
15 | |||
16 | // here you can define custom actions |
||
17 | // all public methods declared in helper class will be available in $I |
||
18 | |||
19 | class Acceptance extends \Codeception\Module |
||
20 | { |
||
21 | public function _initialize() |
||
22 | { |
||
23 | $this->clearDownloadDir(); |
||
24 | } |
||
25 | |||
26 | private function clearDownloadDir() |
||
27 | { |
||
28 | $downloadDir = dirname(__DIR__).'/_downloads/'; |
||
29 | if (file_exists($downloadDir)) { |
||
30 | $files = scandir($downloadDir); |
||
31 | $files = array_filter($files, function ($fileName) use ($downloadDir) { |
||
32 | return is_file($downloadDir.$fileName) && (strpos($fileName, '.') != 0); |
||
33 | }); |
||
34 | foreach ($files as $f) { |
||
35 | unlink($downloadDir.$f); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | public function getBaseUrl() |
||
41 | { |
||
42 | return $this->getModule('WebDriver')->_getUrl(); |
||
0 ignored issues
–
show
|
|||
43 | } |
||
44 | } |
||
45 |
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: