GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WebTranslateItFileService::shouldBeUpdated()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
1
<?php
2
3
namespace Ozean12\WebTranslateItBundle\Service;
4
5
use Ozean12\WebTranslateItBundle\DTO\ProjectFileDTO;
6
7
/**
8
 * Class WebTranslateItFileService.
9
 */
10
class WebTranslateItFileService implements FileServiceInterface
11
{
12
    /**
13
     * @var TranslationRepositoryInterface
14
     */
15
    private $translationRepository;
16
17
    /**
18
     * WebTranslateItFileService constructor.
19
     *
20
     * @param TranslationRepositoryInterface $translationRepository
21
     */
22
    public function __construct(TranslationRepositoryInterface $translationRepository)
23
    {
24
        $this->translationRepository = $translationRepository;
25
    }
26
27
    /**
28
     * Check if file content should be pulled.
29
     *
30
     * If local file does not exist
31
     * OR local file last update datetime is before the remote file update datetime
32
     * OR local file hash is different from the remote file hash
33
     *
34
     * @param string         $realFilePath
35
     * @param ProjectFileDTO $projectFile
36
     *
37
     * @return bool
38
     */
39
    public function shouldBeUpdated($realFilePath, ProjectFileDTO $projectFile)
40
    {
41
        return !file_exists($realFilePath)
42
            || filemtime($realFilePath) < $projectFile->getUpdatedAt()->getTimestamp()
43
            || $projectFile->getHashFile() !== sha1_file($realFilePath)
44
        ;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function update($filePath, ProjectFileDTO $projectFile)
51
    {
52
        $newFileContent = $this->translationRepository->pullFile($projectFile->getName());
53
        file_put_contents($filePath, $newFileContent);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function prepare($directory)
60
    {
61
        if (!file_exists($directory)) {
62
            mkdir($directory);
63
        }
64
    }
65
}
66