Completed
Push — master ( 4f34c8...2960e8 )
by Kamil
23:03 queued 15:59
created

UploadedImagePathGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 9 1
A expandPath() 0 4 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Service\Generator;
15
16
use Sylius\Component\Core\Generator\ImagePathGeneratorInterface;
17
use Sylius\Component\Core\Model\ImageInterface;
18
use Symfony\Component\HttpFoundation\File\UploadedFile;
19
20
final class UploadedImagePathGenerator implements ImagePathGeneratorInterface
21
{
22
    public function generate(ImageInterface $image): string
23
    {
24
        /** @var UploadedFile $file */
25
        $file = $image->getFile();
26
27
        $hash = bin2hex(random_bytes(16));
28
29
        return $this->expandPath($hash . '/' . $file->getClientOriginalName());
30
    }
31
32
    private function expandPath(string $path): string
33
    {
34
        return sprintf('%s/%s/%s', substr($path, 0, 2), substr($path, 2, 2), substr($path, 4));
35
    }
36
}
37