Completed
Pull Request — master (#16)
by Sergii
58:26 queued 08:18
created

JavaScript   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getJavaScriptFileContents() 0 16 3
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Utils;
6
7
/**
8
 * Trait JavaScript.
9
 *
10
 * @package Drupal\TqExtension\Utils
11
 */
12
trait JavaScript
13
{
14
    /**
15
     * @param string $filename
16
     *   Name of file in "src/JavaScript" without ".js" extension.
17
     *
18
     * @return string
19
     *   Contents of file.
20
     */
21
    protected static function getJavaScriptFileContents($filename)
22
    {
23
        static $files = [];
24
25
        if (empty($files[$filename])) {
26
            $path = str_replace('Utils', 'JavaScript', __DIR__) . "/$filename.js";
27
28
            if (!file_exists($path)) {
29
                throw new \RuntimeException(sprintf('File "%s" does not exists!', $path));
30
            }
31
32
            $files[$filename] = file_get_contents($path);
33
        }
34
35
        return $files[$filename];
36
    }
37
}
38