Conditions | 10 |
Paths | 62 |
Total Lines | 66 |
Code Lines | 37 |
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 |
||
21 | public static function saveStatementForInternalLog(Statement $statement): void |
||
22 | { |
||
23 | if (null === $user = self::getUserFromActor($statement->getActor())) { |
||
24 | return; |
||
25 | } |
||
26 | |||
27 | $statementObject = $statement->getObject(); |
||
28 | |||
29 | if (!$statementObject instanceof Activity) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | $languageIso = api_get_language_isocode(); |
||
34 | $statementVerbString = XApiPlugin::extractVerbInLanguage($statement->getVerb()->getDisplay(), $languageIso); |
||
35 | |||
36 | $internalLog = new XApiInternalLog(); |
||
37 | $internalLog |
||
38 | ->setUser($user) |
||
39 | ->setVerb($statementVerbString) |
||
40 | ->setObjectId($statementObject->getId()->getValue()) |
||
41 | ; |
||
42 | |||
43 | if (null !== $statementId = $statement->getId()) { |
||
44 | $internalLog->setStatementId($statementId->getValue()); |
||
45 | } |
||
46 | |||
47 | if (null !== $definition = $statementObject->getDefinition()) { |
||
48 | if (null !== $nameInLanguages = $definition->getName()) { |
||
49 | $internalLog->setActivityName( |
||
50 | XApiPlugin::extractVerbInLanguage($nameInLanguages, $languageIso) |
||
51 | ); |
||
52 | } |
||
53 | |||
54 | if (null !== $descriptionInLanguage = $definition->getDescription()) { |
||
55 | $internalLog->setActivityDescription( |
||
56 | XApiPlugin::extractVerbInLanguage($descriptionInLanguage, $languageIso) |
||
57 | ); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if (null !== $statementResult = $statement->getResult()) { |
||
62 | if (null !== $score = $statementResult->getScore()) { |
||
63 | $internalLog |
||
64 | ->setScoreScaled( |
||
65 | $score->getScaled() |
||
66 | ) |
||
67 | ->setScoreRaw( |
||
68 | $score->getRaw() |
||
69 | ) |
||
70 | ->setScoreMin( |
||
71 | $score->getMin() |
||
72 | ) |
||
73 | ->setScoreMax( |
||
74 | $score->getMax() |
||
75 | ) |
||
76 | ; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | if (null !== $created = $statement->getCreated()) { |
||
81 | $internalLog->setCreatedAt($created); |
||
82 | } |
||
83 | |||
84 | $em = Database::getManager(); |
||
85 | $em->persist($internalLog); |
||
86 | $em->flush(); |
||
87 | } |
||
120 |