Conditions | 2 |
Paths | 2 |
Total Lines | 61 |
Code Lines | 39 |
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 |
||
24 | public function testLinksGenerating() |
||
25 | { |
||
26 | $route = 'random_route_id'; |
||
27 | |||
28 | $target = new TargetDefinition($route); |
||
29 | |||
30 | $registry = new SourceRegistry(); |
||
31 | $registry->add( |
||
32 | 'my_source', |
||
33 | new CollectionSource( |
||
34 | new ArrayCollection( |
||
35 | [ |
||
36 | 'quas', |
||
37 | 'wex', |
||
38 | 'exort', |
||
39 | ] |
||
40 | ) |
||
41 | ) |
||
42 | ); |
||
43 | |||
44 | $normalizer = new DelegatingNormalizer([new ScalarNormalizer()]); |
||
45 | $collection = new RouteCollection(); |
||
46 | $collection->add( |
||
47 | $route, |
||
48 | new Route('/my/{source}') |
||
49 | ); |
||
50 | $generator = new UrlGenerator($collection, new RequestContext()); |
||
51 | |||
52 | $compiler = new SymfonyRouterCompiler($normalizer, null, $generator); |
||
53 | |||
54 | $filler = new CallbackFiller( |
||
55 | ['source'], |
||
56 | function ($items) { |
||
57 | return 'filled_' . array_shift($items); |
||
58 | } |
||
59 | ); |
||
60 | |||
61 | $link = new TargetLink( |
||
62 | $target, |
||
63 | 'My link {{ source }} {{ filler}}', |
||
64 | ['source' => 'my_source'], |
||
65 | ['filler' => $filler] |
||
66 | ); |
||
67 | |||
68 | $resolver = new TargetLinkResolver($registry, $compiler, new CartesianDestinationGenerator()); |
||
69 | /** @var LinkInterface[] $links */ |
||
70 | $links = $resolver->resolve($link); |
||
71 | |||
72 | self::assertCount(3, $links); |
||
73 | $res = []; |
||
74 | foreach ($links as $compiledLink) { |
||
75 | $res[$compiledLink->getHref()] = $compiledLink->getTitle(); |
||
76 | } |
||
77 | |||
78 | self::assertArrayHasKey('/my/quas?filler=filled_quas', $res); |
||
79 | self::assertArrayHasKey('/my/wex?filler=filled_wex', $res); |
||
80 | self::assertArrayHasKey('/my/exort?filler=filled_exort', $res); |
||
81 | self::assertEquals('My link quas filled_quas', $res['/my/quas?filler=filled_quas']); |
||
82 | self::assertEquals('My link wex filled_wex', $res['/my/wex?filler=filled_wex']); |
||
83 | self::assertEquals('My link exort filled_exort', $res['/my/exort?filler=filled_exort']); |
||
84 | } |
||
85 | |||
87 |