1 | <?php |
||
23 | class YumlClient implements YumlClientInterface |
||
24 | { |
||
25 | const YUML_POST_URL = 'https://yuml.me/diagram/%STYLE%/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 | /** |
||
52 | * Get doctrine metadata as yuml. |
||
53 | * |
||
54 | * @param bool $showDetail |
||
55 | * @param array $colors |
||
56 | * @param array $notes |
||
57 | * @return string |
||
58 | */ |
||
59 | 1 | public function makeDslText($showDetail = false, $colors = array(), $notes = array()) |
|
68 | |||
69 | /** |
||
70 | * Use yuml.me to generate an image from yuml. |
||
71 | * |
||
72 | * @param string $dsl_text |
||
73 | * @param string $style the yuml style plain, boring or scruffy |
||
74 | * @param string $extension the file extension to redirect to |
||
75 | * @param string $direction the direction of the graph (LR,RL, TB) |
||
76 | * @param string $scale the graph scale : huge, big, normal, small or tiny. |
||
77 | * |
||
78 | * @return string The url of the generated image. |
||
79 | */ |
||
80 | 1 | public function getGraphUrl($dsl_text, $style, $extension, $direction, $scale) |
|
87 | |||
88 | /** |
||
89 | * @param string $graphUrl |
||
90 | * @param string $filename |
||
91 | * @return mixed |
||
92 | */ |
||
93 | 1 | public function downloadImage($graphUrl, $filename, CurlInterface $curl = null) |
|
100 | |||
101 | /** |
||
102 | * @return ClassMetadata[] |
||
103 | */ |
||
104 | 1 | private function getMetadata() |
|
108 | |||
109 | /** |
||
110 | * @return array |
||
111 | */ |
||
112 | 1 | private function getClasses() |
|
123 | |||
124 | /** |
||
125 | * @param string $style |
||
126 | * @return string |
||
127 | */ |
||
128 | 1 | private function makePostUrl($style, $direction, $scale) |
|
132 | |||
133 | /** |
||
134 | * @param string $return |
||
135 | * @param string $extension |
||
136 | * @return string |
||
137 | */ |
||
138 | 1 | private function makeExtensionUrl($return, $extension) |
|
142 | |||
143 | 1 | private function makeStyle($style, $direction, $scale) |
|
147 | |||
148 | /** |
||
149 | * @param string $direction |
||
150 | * @return string |
||
151 | */ |
||
152 | 1 | private function makeDirection($direction) |
|
162 | |||
163 | /** |
||
164 | * @param string $scale |
||
165 | * @return string |
||
166 | */ |
||
167 | 1 | private function makeScale($scale) |
|
182 | |||
183 | /** |
||
184 | * @param string $extension |
||
185 | * @return string |
||
186 | */ |
||
187 | 1 | private function checkExtension($extension) |
|
199 | |||
200 | 1 | private function checkStyle($style) |
|
210 | } |
||
211 |
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: