Passed
Push — master ( e689f4...c0f464 )
by Gabriel
12:33
created

PaymentsAssets   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 52
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loadAssetContent() 0 11 2
A loadView() 0 3 1
A basePath() 0 3 1
A adminPurchasesSessionsList() 0 7 1
1
<?php
2
3
namespace ByTIC\Payments\Utility;
4
5
use ByTIC\Payments\Application\Library\View\View;
6
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
7
8
/**
9
 * Class PaymentsAssets
10
 * @package ByTIC\Payments\Utility
11
 */
12
class PaymentsAssets
13
{
14
    /**
15
     * @param $path
16
     *
17
     * @return null|string
18
     */
19
    public static function loadAssetContent($path): ?string
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
29
        return '';
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public static function basePath(): string
36
    {
37
        return dirname(dirname(__DIR__));
38
    }
39
40
    /**
41
     * @param IsPurchasableModelTrait $item
42
     *
43
     * @return null|string
44
     */
45
    public static function adminPurchasesSessionsList($item)
46
    {
47
        $sessions = $item->getPurchasesSessions();
48
49
        return self::loadView(
50
            '/admin/purchases_sessions/lists/list-purchase',
51
            ['sessions' => $sessions]
52
        );
53
    }
54
55
    /**
56
     * @param $path
57
     * @param array $variables
58
     *
59
     * @return null|string
60
     */
61
    public static function loadView($path, $variables = [])
62
    {
63
        return View::instance()->load($path, $variables, true);
64
    }
65
}
66