| Conditions | 1 |
| Paths | 1 |
| Total Lines | 127 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 33 | public function testChildGetBreadCrumbs(): void |
||
| 34 | { |
||
| 35 | $menu = $this->prophesize(ItemInterface::class); |
||
| 36 | $menu->getParent()->willReturn(null); |
||
| 37 | |||
| 38 | $dashboardMenu = $this->prophesize(ItemInterface::class); |
||
| 39 | $dashboardMenu->getParent()->willReturn($menu); |
||
| 40 | |||
| 41 | $adminListMenu = $this->prophesize(ItemInterface::class); |
||
| 42 | $adminListMenu->getParent()->willReturn($dashboardMenu); |
||
| 43 | |||
| 44 | $adminSubjectMenu = $this->prophesize(ItemInterface::class); |
||
| 45 | $adminSubjectMenu->getParent()->willReturn($adminListMenu); |
||
| 46 | |||
| 47 | $childMenu = $this->prophesize(ItemInterface::class); |
||
| 48 | $childMenu->getParent()->willReturn($adminSubjectMenu); |
||
| 49 | |||
| 50 | $leafMenu = $this->prophesize(ItemInterface::class); |
||
| 51 | $leafMenu->getParent()->willReturn($childMenu); |
||
| 52 | |||
| 53 | $action = 'my_action'; |
||
| 54 | $breadcrumbsBuilder = new BreadcrumbsBuilder(['child_admin_route' => 'show']); |
||
| 55 | $admin = $this->prophesize(AbstractAdmin::class); |
||
| 56 | $admin->isChild()->willReturn(false); |
||
| 57 | |||
| 58 | $menuFactory = $this->prophesize(MenuFactory::class); |
||
| 59 | $menuFactory->createItem('root')->willReturn($menu); |
||
| 60 | $admin->getMenuFactory()->willReturn($menuFactory); |
||
| 61 | $labelTranslatorStrategy = $this->prophesize( |
||
| 62 | LabelTranslatorStrategyInterface::class |
||
| 63 | ); |
||
| 64 | |||
| 65 | $routeGenerator = $this->prophesize(RouteGeneratorInterface::class); |
||
| 66 | $routeGenerator->generate('sonata_admin_dashboard')->willReturn('/dashboard'); |
||
| 67 | |||
| 68 | $admin->getRouteGenerator()->willReturn($routeGenerator->reveal()); |
||
| 69 | $menu->addChild('link_breadcrumb_dashboard', [ |
||
| 70 | 'uri' => '/dashboard', |
||
| 71 | 'extras' => [ |
||
| 72 | 'translation_domain' => 'SonataAdminBundle', |
||
| 73 | ], |
||
| 74 | ])->willReturn( |
||
| 75 | $dashboardMenu->reveal() |
||
| 76 | ); |
||
| 77 | $labelTranslatorStrategy->getLabel( |
||
| 78 | 'my_class_name_list', |
||
| 79 | 'breadcrumb', |
||
| 80 | 'link' |
||
| 81 | )->willReturn('My class'); |
||
| 82 | $labelTranslatorStrategy->getLabel( |
||
| 83 | 'my_child_class_name_list', |
||
| 84 | 'breadcrumb', |
||
| 85 | 'link' |
||
| 86 | )->willReturn('My child class'); |
||
| 87 | $childAdmin = $this->prophesize(AbstractAdmin::class); |
||
| 88 | $childAdmin->isChild()->willReturn(true); |
||
| 89 | $childAdmin->getParent()->willReturn($admin->reveal()); |
||
| 90 | $childAdmin->getTranslationDomain()->willReturn('ChildBundle'); |
||
| 91 | $childAdmin->getLabelTranslatorStrategy() |
||
| 92 | ->shouldBeCalled() |
||
| 93 | ->willReturn($labelTranslatorStrategy->reveal()); |
||
| 94 | $childAdmin->getClassnameLabel()->willReturn('my_child_class_name'); |
||
| 95 | $childAdmin->hasRoute('list')->willReturn(true); |
||
| 96 | $childAdmin->hasAccess('list')->willReturn(true); |
||
| 97 | $childAdmin->generateUrl('list')->willReturn('/myadmin/my-object/mychildadmin/list'); |
||
| 98 | $childAdmin->getCurrentChildAdmin()->willReturn(null); |
||
| 99 | $childAdmin->hasSubject()->willReturn(true); |
||
| 100 | $childAdmin->getSubject()->willReturn('my subject'); |
||
| 101 | $childAdmin->toString('my subject')->willReturn('My subject'); |
||
| 102 | |||
| 103 | $admin->hasAccess('show', 'my subject')->willReturn(true)->shouldBeCalled(); |
||
| 104 | $admin->hasRoute('show')->willReturn(true); |
||
| 105 | $admin->generateUrl('show', ['id' => 'my-object'])->willReturn('/myadmin/my-object'); |
||
| 106 | |||
| 107 | $admin->trans('My class', [], null)->willReturn('Ma classe'); |
||
| 108 | $admin->hasRoute('list')->willReturn(true); |
||
| 109 | $admin->hasAccess('list')->willReturn(true); |
||
| 110 | $admin->generateUrl('list')->willReturn('/myadmin/list'); |
||
| 111 | $admin->getCurrentChildAdmin()->willReturn($childAdmin->reveal()); |
||
| 112 | $request = $this->prophesize(Request::class); |
||
| 113 | $request->get('slug')->willReturn('my-object'); |
||
| 114 | |||
| 115 | $admin->getIdParameter()->willReturn('slug'); |
||
| 116 | $admin->hasRoute('edit')->willReturn(true); |
||
| 117 | $admin->hasAccess('edit')->willReturn(true); |
||
| 118 | $admin->generateUrl('edit', ['id' => 'my-object'])->willReturn('/myadmin/my-object'); |
||
| 119 | $admin->getRequest()->willReturn($request->reveal()); |
||
| 120 | $admin->hasSubject()->willReturn(true); |
||
| 121 | $admin->getSubject()->willReturn('my subject'); |
||
| 122 | $admin->toString('my subject')->willReturn('My subject'); |
||
| 123 | $admin->getTranslationDomain()->willReturn('FooBundle'); |
||
| 124 | $admin->getLabelTranslatorStrategy()->willReturn( |
||
| 125 | $labelTranslatorStrategy->reveal() |
||
| 126 | ); |
||
| 127 | $admin->getClassnameLabel()->willReturn('my_class_name'); |
||
| 128 | |||
| 129 | $dashboardMenu->addChild('My class', [ |
||
| 130 | 'extras' => [ |
||
| 131 | 'translation_domain' => 'FooBundle', |
||
| 132 | ], |
||
| 133 | 'uri' => '/myadmin/list', |
||
| 134 | ])->shouldBeCalled()->willReturn($adminListMenu->reveal()); |
||
| 135 | |||
| 136 | $adminListMenu->addChild('My subject', [ |
||
| 137 | 'uri' => '/myadmin/my-object', |
||
| 138 | 'extras' => [ |
||
| 139 | 'translation_domain' => false, |
||
| 140 | ], |
||
| 141 | ])->shouldBeCalled()->willReturn($adminSubjectMenu->reveal()); |
||
| 142 | |||
| 143 | $adminSubjectMenu->addChild('My child class', [ |
||
| 144 | 'extras' => [ |
||
| 145 | 'translation_domain' => 'ChildBundle', |
||
| 146 | ], |
||
| 147 | 'uri' => '/myadmin/my-object/mychildadmin/list', |
||
| 148 | ])->shouldBeCalled()->willReturn($childMenu->reveal()); |
||
| 149 | $adminSubjectMenu->setExtra('safe_label', false)->willReturn($childMenu); |
||
| 150 | |||
| 151 | $childMenu->addChild('My subject', [ |
||
| 152 | 'extras' => [ |
||
| 153 | 'translation_domain' => false, |
||
| 154 | ], |
||
| 155 | ])->shouldBeCalled()->willReturn($leafMenu->reveal()); |
||
| 156 | |||
| 157 | $breadcrumbs = $breadcrumbsBuilder->getBreadcrumbs($childAdmin->reveal(), $action); |
||
| 158 | $this->assertCount(5, $breadcrumbs); |
||
|
|
|||
| 159 | } |
||
| 160 | |||
| 294 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: