Conditions | 7 |
Paths | 12 |
Total Lines | 80 |
Code Lines | 54 |
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 |
||
68 | public function process( |
||
69 | IAuthenticationProcess $process, |
||
70 | ?ServerRequestInterface $httpRequest |
||
71 | ): IChallengeResponse { |
||
72 | $form = $this |
||
73 | ->formFactory |
||
74 | ->createBuilder() |
||
75 | ->add('username') |
||
76 | ->add('password', RepeatedType::class, [ |
||
77 | 'constraints' => [ |
||
78 | $this->constraint, |
||
79 | ], |
||
80 | 'type' => PasswordType::class, |
||
81 | 'invalid_message' => 'The password fields must match.', |
||
82 | 'required' => true, |
||
83 | 'first_options' => ['label' => 'Password'], |
||
84 | 'second_options' => ['label' => 'Repeat Password'], |
||
85 | ]) |
||
86 | ->add('submit', SubmitType::class) |
||
87 | ->getForm() |
||
88 | ; |
||
89 | |||
90 | if (null !== $httpRequest) { |
||
91 | $form->handleRequest($this->httpFoundationFactory->createRequest($httpRequest)); |
||
92 | } |
||
93 | |||
94 | if ($form->isSubmitted() && $this->appConfig->isExistingMember($form['username']->getData())) { |
||
95 | $form |
||
96 | ->get('username') |
||
97 | ->addError(new FormError('The username is already taken.')) |
||
98 | ; |
||
99 | } |
||
100 | |||
101 | if ($form->isSubmitted() && $form->isValid()) { |
||
102 | $persistOperations = $process |
||
|
|||
103 | ->getTypedMap() |
||
104 | ->has('persist_operations') ? $process |
||
105 | ->getTypedMap() |
||
106 | ->get('persist_operations', ArrayObject::class) |
||
107 | : new ArrayObject([], PersistOperation::class); |
||
108 | // var_dump(Request::createFromGlobals()); |
||
109 | $member = new Member( |
||
110 | password_hash($form->get('password')->getData(), PASSWORD_DEFAULT), |
||
111 | $form->get('username')->getData() |
||
112 | ); |
||
113 | $newDm = $process |
||
114 | ->getTypedMap() |
||
115 | ->add( |
||
116 | 'member', |
||
117 | $member, |
||
118 | Member::class |
||
119 | ) |
||
120 | ->set( |
||
121 | 'persist_operations', |
||
122 | $persistOperations->add( |
||
123 | new PersistOperation($member, new Operation(Operation::CREATE)), |
||
124 | PersistOperation::class |
||
125 | ), |
||
126 | ArrayObject::class |
||
127 | ) |
||
128 | ; |
||
129 | |||
130 | return new ChallengeResponse( |
||
131 | new AuthenticationProcess($newDm), |
||
132 | null, |
||
133 | false, |
||
134 | true |
||
135 | ) |
||
136 | ; |
||
137 | } |
||
138 | |||
139 | $response = new Response($this->twig->render('credential_registration.html.twig', [ |
||
140 | 'form' => $form->createView(), |
||
141 | ])); |
||
142 | |||
143 | return new ChallengeResponse( |
||
144 | $process, |
||
145 | $response, |
||
146 | false, |
||
147 | false |
||
148 | ) |
||
152 |