Conditions | 9 |
Paths | 11 |
Total Lines | 60 |
Code Lines | 33 |
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 |
||
27 | private ManagerRegistry $managerRegistry, |
||
28 | private TranslatorInterface $translator, |
||
29 | ) {} |
||
30 | |||
31 | #[Route(path: '/lti/os', name: 'chamilo_lti_os')] |
||
32 | public function outcomeService(Request $request): Response |
||
33 | { |
||
34 | $em = $this->managerRegistry->getManager(); |
||
35 | $toolRepo = $em->getRepository(ExternalTool::class); |
||
36 | |||
37 | $headers = $request->headers; |
||
38 | |||
39 | if (empty($headers->get('authorization'))) { |
||
40 | throw $this->createAccessDeniedException(); |
||
41 | } |
||
42 | |||
43 | $authParams = OAuthUtil::split_header($headers['Authorization']); |
||
44 | |||
45 | if (empty($authParams) || empty($authParams['oauth_consumer_key']) || empty($authParams['oauth_signature'])) { |
||
46 | throw $this->createAccessDeniedException(); |
||
47 | } |
||
48 | |||
49 | $course = $this->getCourse(); |
||
50 | $tools = $toolRepo->findBy([ |
||
51 | 'consumerKey' => $authParams['oauth_consumer_key'], |
||
52 | ]); |
||
53 | $url = $this->generateUrl('chamilo_lti_os', [ |
||
54 | 'code' => $course->getCode(), |
||
55 | ]); |
||
56 | |||
57 | $toolIsFound = false; |
||
58 | |||
59 | /** @var ExternalTool $tool */ |
||
60 | foreach ($tools as $tool) { |
||
61 | $signatureIsValid = $this->compareRequestSignature( |
||
62 | $url, |
||
63 | $authParams['oauth_consumer_key'], |
||
64 | $authParams['oauth_signature'], |
||
65 | $tool |
||
66 | ); |
||
67 | |||
68 | if ($signatureIsValid) { |
||
69 | $toolIsFound = true; |
||
70 | |||
71 | break; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | if (!$toolIsFound) { |
||
76 | throw $this->createNotFoundException('External tool not found. Signature is not valid'); |
||
77 | } |
||
78 | |||
79 | $body = file_get_contents('php://input'); |
||
80 | $bodyHash = base64_encode(sha1($body, true)); |
||
81 | |||
82 | if ($bodyHash !== $authParams['oauth_body_hash']) { |
||
83 | throw $this->createAccessDeniedException('Request is not valid.'); |
||
84 | } |
||
85 | |||
86 | $process = $this->processServiceRequest(); |
||
87 | |||
146 |