Completed
Push — master ( d998d0...abb41b )
by Kamil
38:34
created

OrderingTranslationFilesFinder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findTranslationFiles() 0 17 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Translation\Finder;
13
14
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class OrderingTranslationFilesFinder implements TranslationFilesFinderInterface
20
{
21
    /**
22
     * @var TranslationFilesFinderInterface
23
     */
24
    private $translationFilesFinder;
25
26
    /**
27
     * @param TranslationFilesFinderInterface $translationFilesFinder
28
     */
29
    public function __construct(TranslationFilesFinderInterface $translationFilesFinder)
30
    {
31
        $this->translationFilesFinder = $translationFilesFinder;
32
    }
33
34
    public function findTranslationFiles(ThemeInterface $theme)
35
    {
36
        $files = $this->translationFilesFinder->findTranslationFiles($theme);
37
38
        /**
39
         * PHP 5.* bug, fixed in PHP 7: https://bugs.php.net/bug.php?id=50688
40
         * "usort(): Array was modified by the user comparison function"
41
         */
42
        @usort($files, function ($firstFile, $secondFile) use ($theme) {
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
43
            $firstFile = str_replace($theme->getPath(), '', $firstFile);
44
            $secondFile = str_replace($theme->getPath(), '', $secondFile);
45
46
            return strpos($secondFile, 'translations') - strpos($firstFile, 'translations');
47
        });
48
49
        return $files;
50
    }
51
}
52