getBasePathForMediaConversion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\MediaLibrary\PathGenerator;
4
5
use ByTIC\MediaLibrary\Media\Media;
6
7
/**
8
 * Class AbstractPathGenerator.
9
 */
10
abstract class AbstractPathGenerator
11
{
12
    /**
13
     * @param Media $media
14
     *
15
     * @return string
16
     */
17 2
    public static function getBasePathForMediaOriginal($media)
18
    {
19 2
        $basePath = self::getBasePathForMedia($media);
20 2
        $originalPath = $media->getCollection()->getOriginalPath();
21 2
        if (!empty($originalPath)) {
22
            $basePath .= DIRECTORY_SEPARATOR . $media->getCollection()->getOriginalPath();
23
        }
24
25 2
        return $basePath;
26
    }
27
28
    /**
29
     * @param Media $media
30
     *
31
     * @return string
32
     */
33 7
    public static function getBasePathForMedia($media)
34
    {
35 7
        return '/' . $media->getCollection()->getName()
36 7
            . '/' . static::getFolderNameForMedia($media)
37 7
            . '/' . $media->getModel()->getPrimaryKey()
38 7
            . '/';
39
    }
40
41
    /**
42
     * @param Media $media
43
     *
44
     * @return string
45
     */
46 7
    public static function getFolderNameForMedia($media)
47
    {
48 7
        $model = $media->getModel();
49 7
        if (method_exists($model, 'getFolderNameForMedia')) {
50 7
            return $model->getFolderNameForMedia();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model->getFolderNameForMedia() returns the type Nip\Records\AbstractMode...\Collections\Collection which is incompatible with the documented return type string.
Loading history...
51
        }
52
53
        return $media->getModel()->getManager()->getTable();
54
    }
55
56
    /**
57
     * @param Media  $media
58
     * @param string $conversionName
59
     *
60
     * @return string
61
     */
62
    public static function getBasePathForMediaConversion($media, $conversionName)
63
    {
64
        return self::getBasePathForMedia($media) . DIRECTORY_SEPARATOR . $conversionName;
65
    }
66
}
67