| Conditions | 9 | 
| Paths | 15 | 
| Total Lines | 78 | 
| Code Lines | 52 | 
| 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  | 
            ||
| 54 | public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate = null)  | 
            ||
| 55 |     { | 
            ||
| 56 | $content = file_get_contents($fileName);  | 
            ||
| 57 |         $content = str_replace("\xFF\xFE", '', $content); // remove UTF16(LE) BOM | 
            ||
| 58 | $content = mb_convert_encoding($content, 'UTF-8', 'UCS-2LE');  | 
            ||
| 59 | // unify line feeds  | 
            ||
| 60 |         $content = str_replace("\r\n", "\n", $content); | 
            ||
| 61 |         $rows = ArrayUtil::explodeTrim("\"\n", $content); | 
            ||
| 62 | $notFoundGeocacheCodes = [];  | 
            ||
| 63 |         foreach ($rows as $row) { | 
            ||
| 64 | $data = str_getcsv($row, ',', '"', '""');  | 
            ||
| 65 |             if (count($data) !== 4) { | 
            ||
| 66 | throw new WrongFileFormatException(  | 
            ||
| 67 |                     $this->translator->trans('field_notes.error.wrong_file_format') | 
            ||
| 68 | );  | 
            ||
| 69 | }  | 
            ||
| 70 | |||
| 71 | $date = $this->getDate($data[1]);  | 
            ||
| 72 | |||
| 73 |             if ($ignoreBeforeDate !== null && $date < $ignoreBeforeDate) { | 
            ||
| 74 | continue;  | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 |             if (!array_key_exists($data[2], self::LOG_TYPE)) { | 
            ||
| 78 | $this->addError(  | 
            ||
| 79 |                     /** @Desc("Log type ""%type%"" is not implemented.") */ | 
            ||
| 80 |                     $this->translator->trans('field_notes.error.log_type_not_implemented', ['%type%' => $data[2]]) | 
            ||
| 81 | );  | 
            ||
| 82 | continue;  | 
            ||
| 83 | }  | 
            ||
| 84 | $type = self::LOG_TYPE[$data[2]];  | 
            ||
| 85 | |||
| 86 |             if (0 === stripos($data[0], 'GC')) { | 
            ||
| 87 | $query = $this->entityManager->createQueryBuilder()  | 
            ||
| 88 |                     ->select('g') | 
            ||
| 89 | ->from(Geocache::class, 'g')  | 
            ||
| 90 |                     ->where("IFELSE(g.wpGcMaintained = '', g.wpGc, g.wpGcMaintained) = :code") | 
            ||
| 91 |                     ->setParameter('code', $data[0]) | 
            ||
| 92 | ->getQuery();  | 
            ||
| 93 | $geocache = $query->getOneOrNullResult();  | 
            ||
| 94 |             } else { | 
            ||
| 95 | $geocache = $this->entityManager->getRepository(Geocache::class)->findOneBy(['wpOc' => $data[0]]);  | 
            ||
| 96 | }  | 
            ||
| 97 |             if (!$geocache) { | 
            ||
| 98 | $notFoundGeocacheCodes[] = $data[0];  | 
            ||
| 99 | $this->addError(  | 
            ||
| 100 |                     /** @Desc("Geocache ""%code%"" not found.") */ | 
            ||
| 101 | $this->translator->transChoice(  | 
            ||
| 102 | 'field_notes.error.geocache_not_found',  | 
            ||
| 103 | count($notFoundGeocacheCodes),  | 
            ||
| 104 | [  | 
            ||
| 105 | '%code%' => ArrayUtil::humanImplode(  | 
            ||
| 106 | $notFoundGeocacheCodes,  | 
            ||
| 107 |                                 $this->translator->trans('array_util.human_lang_implode.and') | 
            ||
| 108 | ),  | 
            ||
| 109 | ]  | 
            ||
| 110 | ),  | 
            ||
| 111 | 'geocache-not-found'  | 
            ||
| 112 | );  | 
            ||
| 113 | continue;  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | $fieldNote = new FieldNote();  | 
            ||
| 117 | $fieldNote->setUser($this->entityManager->getReference(User::class, $userId));  | 
            ||
| 118 | $fieldNote->setGeocache($geocache);  | 
            ||
| 119 | $fieldNote->setDate($date);  | 
            ||
| 120 | $fieldNote->setType($type);  | 
            ||
| 121 | $fieldNote->setText($data[3]);  | 
            ||
| 122 | $this->entityManager->persist($fieldNote);  | 
            ||
| 123 | }  | 
            ||
| 124 | $this->entityManager->flush();  | 
            ||
| 125 | |||
| 126 |         if ($this->hasErrors()) { | 
            ||
| 127 | return false;  | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 | return true;  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 199 |