Completed
Push — master ( 6a1d7c...5e042f )
by Gabriel
06:31
created

MediaModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 11.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 51
ccs 2
cts 17
cp 0.1176
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loadAssetContent() 0 11 2
A basePath() 0 4 1
A getAdminImagesGridForModel() 0 9 1
A loadView() 0 4 1
1
<?php
2
3
namespace ByTIC\Modules\MediaLibrary;
4
5
use ByTIC\MediaLibrary\HasMedia\HasMediaTrait;
6
use ByTIC\Modules\MediaLibrary\Application\Library\View\View;
7
8
/**
9
 * Class MediaModule
10
 * @package ByTIC\Modules\MediaLibrary
11
 */
12
class MediaModule
13
{
14
15
    /**
16
     * @param $path
17
     * @return null|string
18
     */
19
    public static function loadAssetContent($path)
20
    {
21
        $fullPath = self::basePath()
22
            . DIRECTORY_SEPARATOR . 'resources'
23
            . DIRECTORY_SEPARATOR . 'assets'
24
            . $path;
25
        if (file_exists($fullPath)) {
26
            return file_get_contents($fullPath);
27
        }
28
        return '';
29
    }
30
31
    /**
32
     * @return string
33
     */
34 1
    public static function basePath()
35
    {
36 1
        return dirname(__DIR__);
37
    }
38
39
    /**
40
     * @param HasMediaTrait $item
0 ignored issues
show
introduced by
The type HasMediaTrait for parameter $item is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
41
     * @return null|string
42
     */
43
    public static function getAdminImagesGridForModel($item)
44
    {
45
        $images = $item->getImages();
46
47
        return self::loadView(
48
            '/admin/gallery/images-grid',
49
            ['item' => $item, 'images' => $images]
50
        );
51
    }
52
53
    /**
54
     * @param $path
55
     * @param array $variables
56
     * @return null|string
57
     */
58
    public static function loadView($path, $variables = [])
59
    {
60
        return View::instance()->load($path, $variables, true);
61
    }
62
}
63