| Conditions | 1 |
| Paths | 1 |
| Total Lines | 208 |
| Code Lines | 131 |
| 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 |
||
| 40 | public function validPropertyTypesProvider() : iterable |
||
| 41 | { |
||
| 42 | yield 'empty' => [ |
||
|
|
|||
| 43 | <<<'PHPDOC' |
||
| 44 | /** */ |
||
| 45 | PHPDOC |
||
| 46 | , |
||
| 47 | new MixedType(), |
||
| 48 | ]; |
||
| 49 | |||
| 50 | yield 'only comment' => [ |
||
| 51 | <<<'PHPDOC' |
||
| 52 | /** Hello world */ |
||
| 53 | PHPDOC |
||
| 54 | , |
||
| 55 | new MixedType(), |
||
| 56 | ]; |
||
| 57 | |||
| 58 | yield 'no type' => [ |
||
| 59 | <<<'PHPDOC' |
||
| 60 | /** @var */ |
||
| 61 | PHPDOC |
||
| 62 | , |
||
| 63 | new MixedType(), |
||
| 64 | ]; |
||
| 65 | |||
| 66 | yield 'int' => [ |
||
| 67 | <<<'PHPDOC' |
||
| 68 | /** @var int */ |
||
| 69 | PHPDOC |
||
| 70 | , |
||
| 71 | new IntegerType(), |
||
| 72 | ]; |
||
| 73 | |||
| 74 | yield 'int with description' => [ |
||
| 75 | <<<'PHPDOC' |
||
| 76 | /** @var int Hello world */ |
||
| 77 | PHPDOC |
||
| 78 | , |
||
| 79 | new IntegerType(), |
||
| 80 | ]; |
||
| 81 | |||
| 82 | yield '?int' => [ |
||
| 83 | <<<'PHPDOC' |
||
| 84 | /** @var ?int */ |
||
| 85 | PHPDOC |
||
| 86 | , |
||
| 87 | new UnionType(new IntegerType(), new NullType()), |
||
| 88 | ]; |
||
| 89 | |||
| 90 | yield 'int|null' => [ |
||
| 91 | <<<'PHPDOC' |
||
| 92 | /** @var int|null */ |
||
| 93 | PHPDOC |
||
| 94 | , |
||
| 95 | new UnionType(new IntegerType(), new NullType()), |
||
| 96 | ]; |
||
| 97 | |||
| 98 | yield 'null|int' => [ |
||
| 99 | <<<'PHPDOC' |
||
| 100 | /** @var null|int */ |
||
| 101 | PHPDOC |
||
| 102 | , |
||
| 103 | new UnionType(new NullType(), new IntegerType()), |
||
| 104 | ]; |
||
| 105 | |||
| 106 | yield 'int[]' => [ |
||
| 107 | <<<'PHPDOC' |
||
| 108 | /** @var int[] */ |
||
| 109 | PHPDOC |
||
| 110 | , |
||
| 111 | new ListType(new IntegerType()), |
||
| 112 | ]; |
||
| 113 | |||
| 114 | yield 'int[]|null' => [ |
||
| 115 | <<<'PHPDOC' |
||
| 116 | /** @var int[]|null */ |
||
| 117 | PHPDOC |
||
| 118 | , |
||
| 119 | new UnionType(new ListType(new IntegerType()), new NullType()), |
||
| 120 | ]; |
||
| 121 | |||
| 122 | yield 'array' => [ |
||
| 123 | <<<'PHPDOC' |
||
| 124 | /** @var array */ |
||
| 125 | PHPDOC |
||
| 126 | , |
||
| 127 | new MapType(new UnionType(new IntegerType(), new StringType()), new MixedType()), |
||
| 128 | ]; |
||
| 129 | |||
| 130 | yield 'array<int>' => [ |
||
| 131 | <<<'PHPDOC' |
||
| 132 | /** @var array<int> */ |
||
| 133 | PHPDOC |
||
| 134 | , |
||
| 135 | new ListType(new IntegerType()), |
||
| 136 | ]; |
||
| 137 | |||
| 138 | yield 'array<int>|null' => [ |
||
| 139 | <<<'PHPDOC' |
||
| 140 | /** @var array<int>|null */ |
||
| 141 | PHPDOC |
||
| 142 | , |
||
| 143 | new UnionType(new ListType(new IntegerType()), new NullType()), |
||
| 144 | ]; |
||
| 145 | |||
| 146 | yield 'array<int, string>' => [ |
||
| 147 | <<<'PHPDOC' |
||
| 148 | /** @var array<int, string> */ |
||
| 149 | PHPDOC |
||
| 150 | , |
||
| 151 | new MapType(new IntegerType(), new StringType()), |
||
| 152 | ]; |
||
| 153 | |||
| 154 | yield 'array<int, string>|null' => [ |
||
| 155 | <<<'PHPDOC' |
||
| 156 | /** @var array<int, string>|null */ |
||
| 157 | PHPDOC |
||
| 158 | , |
||
| 159 | new UnionType(new MapType(new IntegerType(), new StringType()), new NullType()), |
||
| 160 | ]; |
||
| 161 | |||
| 162 | yield 'int[][]' => [ |
||
| 163 | <<<'PHPDOC' |
||
| 164 | /** @var int[][] */ |
||
| 165 | PHPDOC |
||
| 166 | , |
||
| 167 | new ListType(new ListType(new IntegerType())), |
||
| 168 | ]; |
||
| 169 | |||
| 170 | yield 'int[][]|null' => [ |
||
| 171 | <<<'PHPDOC' |
||
| 172 | /** @var int[][]|null */ |
||
| 173 | PHPDOC |
||
| 174 | , |
||
| 175 | new UnionType(new ListType(new ListType(new IntegerType())), new NullType()), |
||
| 176 | ]; |
||
| 177 | |||
| 178 | yield 'int[]string[]' => [ |
||
| 179 | <<<'PHPDOC' |
||
| 180 | /** @var int[]|string[] */ |
||
| 181 | PHPDOC |
||
| 182 | , |
||
| 183 | new UnionType(new ListType(new IntegerType()), new ListType(new StringType())), |
||
| 184 | ]; |
||
| 185 | |||
| 186 | yield 'SomeType' => [ |
||
| 187 | <<<'PHPDOC' |
||
| 188 | /** @var SomeType */ |
||
| 189 | PHPDOC |
||
| 190 | , |
||
| 191 | new ObjectType('SomeType'), |
||
| 192 | ]; |
||
| 193 | |||
| 194 | yield '(SomeClass&SomeInterface)|null' => [ |
||
| 195 | <<<'PHPDOC' |
||
| 196 | /** @var (SomeClass&SomeInterface)|null */ |
||
| 197 | PHPDOC |
||
| 198 | , |
||
| 199 | new UnionType( |
||
| 200 | new IntersectionType( |
||
| 201 | new ObjectType('SomeClass'), |
||
| 202 | new ObjectType('SomeInterface') |
||
| 203 | ), |
||
| 204 | new NullType() |
||
| 205 | ), |
||
| 206 | ]; |
||
| 207 | |||
| 208 | yield 'SomeClass|(AnotherClass&(AnotherFooInterface|AnotherBarInterface))|null' => [ |
||
| 209 | <<<'PHPDOC' |
||
| 210 | /** @var SomeClass|(AnotherClass&(AnotherFooInterface|AnotherBarInterface))|null */ |
||
| 211 | PHPDOC |
||
| 212 | , |
||
| 213 | new UnionType( |
||
| 214 | new ObjectType('SomeClass'), |
||
| 215 | new IntersectionType( |
||
| 216 | new ObjectType('AnotherClass'), |
||
| 217 | new UnionType( |
||
| 218 | new ObjectType('AnotherFooInterface'), |
||
| 219 | new ObjectType('AnotherBarInterface') |
||
| 220 | ) |
||
| 221 | ), |
||
| 222 | new NullType() |
||
| 223 | ), |
||
| 224 | ]; |
||
| 225 | |||
| 226 | yield 'FooBar alias' => [ |
||
| 227 | <<<'PHPDOC' |
||
| 228 | /** @var FooBar */ |
||
| 229 | PHPDOC |
||
| 230 | , |
||
| 231 | new ObjectType('FooBaz'), |
||
| 232 | ]; |
||
| 233 | |||
| 234 | yield 'double' => [ |
||
| 235 | <<<'PHPDOC' |
||
| 236 | /** @var double */ |
||
| 237 | PHPDOC |
||
| 238 | , |
||
| 239 | new FloatType(), |
||
| 240 | ]; |
||
| 241 | |||
| 242 | yield 'real' => [ |
||
| 243 | <<<'PHPDOC' |
||
| 244 | /** @var real */ |
||
| 245 | PHPDOC |
||
| 246 | , |
||
| 247 | new FloatType(), |
||
| 248 | ]; |
||
| 251 |