Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
99 | public function testCreateQueryBuilderForCollection() |
||
100 | { |
||
101 | $this->classMetadata |
||
102 | ->expects($this->once()) |
||
103 | ->method('getFieldNames') |
||
104 | ->will($this->returnValue([])); |
||
105 | |||
106 | $this->classMetadata |
||
107 | ->expects($this->once()) |
||
108 | ->method('getAssociationTargetClass') |
||
109 | ->with($this->identicalTo('translations')) |
||
110 | ->will($this->returnValue($translationClass = TranslationTest::class)); |
||
111 | |||
112 | $translationClassMetadata = $this->createClassMetadataMock(); |
||
113 | $translationClassMetadata |
||
114 | ->expects($this->once()) |
||
115 | ->method('getFieldNames') |
||
116 | ->will($this->returnValue(['locale'])); |
||
117 | |||
118 | $this->documentManager |
||
119 | ->expects($this->once()) |
||
120 | ->method('getClassMetadata') |
||
121 | ->with($this->identicalTo($translationClass)) |
||
122 | ->will($this->returnValue($translationClassMetadata)); |
||
123 | |||
124 | $this->documentManager |
||
125 | ->expects($this->once()) |
||
126 | ->method('createQueryBuilder') |
||
127 | ->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock())); |
||
128 | |||
129 | $queryBuilder |
||
130 | ->expects($this->once()) |
||
131 | ->method('field') |
||
132 | ->with($this->identicalTo('translations.locale')) |
||
133 | ->will($this->returnSelf()); |
||
134 | |||
135 | $this->localeContext |
||
136 | ->expects($this->once()) |
||
137 | ->method('getLocales') |
||
138 | ->will($this->returnValue($locales = ['fr'])); |
||
139 | |||
140 | $this->localeContext |
||
141 | ->expects($this->once()) |
||
142 | ->method('getFallbackLocale') |
||
143 | ->will($this->returnValue($fallbackLocale = 'en')); |
||
144 | |||
145 | $queryBuilder |
||
146 | ->expects($this->once()) |
||
147 | ->method('in') |
||
148 | ->with($this->identicalTo(array_merge($locales, [$fallbackLocale]))) |
||
149 | ->will($this->returnSelf()); |
||
150 | |||
151 | $this->assertSame($queryBuilder, $this->translatableRepository->createQueryBuilderForCollection()); |
||
152 | } |
||
153 | |||
218 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: