1 | <?php |
||
23 | class YumlClient implements YumlClientInterface |
||
24 | { |
||
25 | const YUML_POST_URL = 'https://yuml.me/diagram/plain/class'; |
||
26 | const YUML_REDIRECT_URL = 'https://yuml.me/'; |
||
27 | |||
28 | protected $entityManager; |
||
29 | |||
30 | protected $metadataFactory; |
||
31 | |||
32 | protected $metadataGrapher; |
||
33 | |||
34 | /** |
||
35 | * @param EntityManagerInterface $entityManager |
||
36 | * @param ClassMetadataFactoryInterface|null $classMetadataFactory |
||
37 | * @param MetadataGrapherInterface|null $metadataGrapher |
||
38 | */ |
||
39 | 4 | public function __construct( |
|
49 | |||
50 | /** |
||
51 | * Get doctrine metadata as yuml. |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function makeDslText() |
|
59 | |||
60 | /** |
||
61 | * Use yuml.me to generate an image from yuml. |
||
62 | * |
||
63 | * @param string $dsl_text |
||
64 | * |
||
65 | * @return string The url of the generated image. |
||
66 | */ |
||
67 | 1 | public function getGraphUrl($dsl_text) |
|
75 | |||
76 | /** |
||
77 | * @param string $graphUrl |
||
78 | * @param string $filename |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 1 | public function downloadImage($graphUrl, $filename, CurlInterface $curl = null) |
|
88 | |||
89 | /** |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | private function getMetadata() |
|
96 | |||
97 | /** |
||
98 | * @return array |
||
99 | */ |
||
100 | 1 | private function getClasses() |
|
111 | |||
112 | /** |
||
113 | * @param $classes |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 1 | private function generateGraph($classes) |
|
123 | } |
||
124 |
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: