Completed
Push — master ( c52783...cd75c7 )
by Gabriel
06:40 queued 10s
created

AbstractPathGenerator::getFolderNameForMedia()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
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
    public static function getBasePathForMediaOriginal($media)
18
    {
19
        $basePath = self::getBasePathForMedia($media);
20
        $originalPath = $media->getCollection()->getOriginalPath();
21
        if (!empty($originalPath)) {
22
            $basePath .= DIRECTORY_SEPARATOR.$media->getCollection()->getOriginalPath();
23
        }
24
25
        return $basePath;
26
    }
27
28
    /**
29
     * @param Media $media
30
     *
31
     * @return string
32
     */
33
    public static function getBasePathForMedia($media)
34
    {
35
        return '/'.$media->getCollection()->getName()
36
            .'/'.static::getFolderNameForMedia($media)
37
            .'/'.$media->getModel()->getPrimaryKey()
0 ignored issues
show
Bug introduced by
Are you sure $media->getModel()->getPrimaryKey() of type array|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
            .'/'./** @scrutinizer ignore-type */ $media->getModel()->getPrimaryKey()
Loading history...
38
            .'/';
39
    }
40
41
    /**
42
     * @param Media $media
43
     *
44
     * @return string
45
     */
46
    public static function getFolderNameForMedia($media)
47
    {
48
        $model = $media->getModel();
49
        if (method_exists($model, 'getFolderNameForMedia')) {
50
            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