1 | <?php |
||
31 | class InvoicesController extends AbstractOrdersController |
||
32 | { |
||
33 | /** |
||
34 | * Lists all Orders entities. |
||
35 | * |
||
36 | * @Route("/", name="invoices") |
||
37 | * @Method("GET") |
||
38 | * @Template() |
||
39 | */ |
||
40 | public function indexAction(Request $request) |
||
51 | |||
52 | /** |
||
53 | * Finds and displays a Orders entity. |
||
54 | * |
||
55 | * @Route("/{id}/show", name="invoices_show", requirements={"id"="\d+"}) |
||
56 | * @Method("GET") |
||
57 | * @Template() |
||
58 | */ |
||
59 | public function showAction(Orders $orders) |
||
65 | |||
66 | /** |
||
67 | * Displays a form to edit an existing Orders entity. |
||
68 | * |
||
69 | * @Route("/admin/{id}/edit", name="invoices_edit", requirements={"id"="\d+"}) |
||
70 | * @Method("GET") |
||
71 | * @Template() |
||
72 | */ |
||
73 | public function editAction(Orders $orders) |
||
79 | |||
80 | /** |
||
81 | * Edits an existing Orders entity. |
||
82 | * |
||
83 | * @Route("/admin/{id}/update", name="invoices_update", requirements={"id"="\d+"}) |
||
84 | * @Method("PUT") |
||
85 | * @Template("orders/invoices/edit.html.twig") |
||
86 | */ |
||
87 | public function updateAction(Orders $orders, Request $request) |
||
98 | |||
99 | /** |
||
100 | * Print the current invoice.<br />Creating a `PDF` file for viewing on paper |
||
101 | * |
||
102 | * @Route("/{id}/print/", name="invoices_print", requirements={"id"="\d+"}) |
||
103 | * @Method("GET") |
||
104 | * @Template() |
||
105 | * |
||
106 | * @param \App\Entity\Orders $orders Order item to print |
||
107 | * @return \Symfony\Component\HttpFoundation\Response |
||
108 | */ |
||
109 | public function printAction(Orders $orders) |
||
115 | } |
||
116 |
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: