Conditions | 8 |
Paths | 128 |
Total Lines | 59 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
94 | final public function createVisitors(int $flags = 0): VisitorInterface |
||
95 | { |
||
96 | $flag = function (int $needle) use ($flags) { |
||
97 | return ($needle & $flags) == $needle; |
||
98 | }; |
||
99 | |||
100 | $errorObj = new ErrorObject(); |
||
101 | $container = new VisitorContainer($errorObj); |
||
102 | |||
103 | if (!$flag(self::VISITOR_IGNORE_BASIC_VALIDATION)) { |
||
104 | $container->addVisitor(new NumberVisitor($errorObj)); |
||
105 | $container->addVisitor(new TextVisitor($errorObj)); |
||
106 | } |
||
107 | |||
108 | if (!$flag(self::VISITOR_IGNORE_MESSAGES)) { |
||
109 | $container->addVisitor(new MessageVisitor($errorObj)); |
||
110 | } |
||
111 | |||
112 | if (!$flag(self::VISITOR_IGNORE_DATES)) { |
||
113 | $container->addVisitor(new DateVisitor($errorObj)); |
||
114 | } |
||
115 | |||
116 | if (!$flag(self::VISITOR_IGNORE_ACCOUNTS)) { |
||
117 | $container->addVisitor( |
||
118 | new AccountVisitor( |
||
119 | $errorObj, |
||
120 | new DelegatingFactory(new AccountFactory(), new BankgiroFactory()), |
||
121 | new BankgiroFactory() |
||
122 | ) |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | if (!$flag(self::VISITOR_IGNORE_AMOUNTS)) { |
||
127 | $container->addVisitor( |
||
128 | new AmountVisitor( |
||
129 | $errorObj, |
||
130 | new SignalMoneyParser() |
||
131 | ) |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | if (!$flag(self::VISITOR_IGNORE_IDS)) { |
||
136 | $container->addVisitor( |
||
137 | new StateIdVisitor( |
||
138 | $errorObj, |
||
139 | new OrganizationIdFactory(), |
||
140 | new PersonalIdFactory(new CoordinationIdFactory(new NullIdFactory())) |
||
141 | ) |
||
142 | ); |
||
143 | } |
||
144 | |||
145 | if (!$flag(self::VISITOR_IGNORE_STRICT_VALIDATION)) { |
||
146 | $container->addVisitor(new PaymentVisitor($errorObj)); |
||
147 | $container->addVisitor(new PayeeVisitor($errorObj)); |
||
148 | $container->addVisitor(new CountingVisitor($errorObj)); |
||
149 | $container->addVisitor(new SummaryVisitor($errorObj)); |
||
150 | } |
||
151 | |||
152 | return $container; |
||
153 | } |
||
155 |