1 | <?php |
||
22 | class ValidateProjectStep implements Step { |
||
23 | /** |
||
24 | * Project to validate. |
||
25 | * |
||
26 | * @var Project |
||
27 | */ |
||
28 | protected $project; |
||
29 | |||
30 | /** |
||
31 | * Initialiser. |
||
32 | * |
||
33 | * @param Project $project |
||
34 | */ |
||
35 | public function __construct(Project $project) { |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc Step |
||
41 | */ |
||
42 | public function execute($task, LoggerInterface $logger) { |
||
83 | |||
84 | /** |
||
85 | * Does the supplied component have a valid name? |
||
86 | * |
||
87 | * @param ComponentSpecification $componentSpecification |
||
88 | * |
||
89 | * @return boolean |
||
90 | */ |
||
91 | protected function isValidComponentName(ComponentSpecification $componentSpecification) { |
||
95 | |||
96 | /** |
||
97 | * Is the supplied component's package repository known to us? |
||
98 | * |
||
99 | * @param ComponentSpecification $componentSpecification |
||
100 | * @param PackageRepository[] $packageRepositories |
||
101 | * |
||
102 | * @return boolean |
||
103 | */ |
||
104 | protected function isValidPackageRepository(ComponentSpecification $componentSpecification, $packageRepositories) { |
||
108 | |||
109 | /** |
||
110 | * Is the supplied component's specification complete? |
||
111 | * |
||
112 | * @param ComponentSpecification $componentSpecification |
||
113 | * |
||
114 | * @return boolean |
||
115 | */ |
||
116 | protected function isComponentSpecificationComplete(ComponentSpecification $componentSpecification) { |
||
120 | } |
||
121 |
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 implementation 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 interface: