| Conditions | 9 |
| Paths | 32 |
| Total Lines | 66 |
| Code Lines | 36 |
| 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 |
||
| 20 | public static function saveStatementForInternalLog(Statement $statement) |
||
| 21 | { |
||
| 22 | if (null === $user = self::getUserFromActor($statement->getActor())) { |
||
| 23 | return; |
||
| 24 | } |
||
| 25 | |||
| 26 | $internalLog = new InternalLog(); |
||
| 27 | $internalLog->setUser($user); |
||
| 28 | |||
| 29 | $languageIso = api_get_language_isocode(); |
||
| 30 | |||
| 31 | $internalLog->setVerb( |
||
| 32 | XApiPlugin::extractVerbInLanguage($statement->getVerb()->getDisplay(), $languageIso) |
||
| 33 | ); |
||
| 34 | |||
| 35 | $statementObject = $statement->getObject(); |
||
| 36 | |||
| 37 | if (!$statementObject instanceof Activity) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | $internalLog->setStatementId($statement->getId()->getValue()); |
||
| 42 | |||
| 43 | if (null !== $definition = $statementObject->getDefinition()) { |
||
| 44 | $internalLog->setActivityId( |
||
| 45 | $statementObject->getId()->getValue() |
||
| 46 | ); |
||
| 47 | |||
| 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 | if (null !== $created = $statement->getCreated()) { |
||
| 80 | $internalLog->setCreatedAt($created); |
||
| 81 | } |
||
| 82 | |||
| 83 | $em = Database::getManager(); |
||
| 84 | $em->persist($internalLog); |
||
| 85 | $em->flush(); |
||
| 86 | } |
||
| 119 |