Test Failed
Push — main ( d7f1b4...976a1c )
by Guillaume
02:42
created

VueManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addVue() 0 2 1
A __construct() 0 3 1
A getInstance() 0 5 2
A addImport() 0 2 1
A __toString() 0 4 1
1
<?php
2
namespace PHPMV;
3
4
use PHPMV\js\JavascriptUtils;
5
6
class VueManager{
7
8
    private static ?VueManager $instance = null;
9
    protected array $imports;
10
    protected array $vues;
11
12
    protected function __construct() {
13
        $this->imports = [];
14
        $this->vues = [];
15
    }
16
17
    public static function getInstance():VueManager {
18
        if (!isset(self::$instance)) {
19
            self::$instance = new VueManager();
20
        }
21
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type null which is incompatible with the type-hinted return PHPMV\VueManager. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    public function addImport($import):void {
25
        $this->imports[] = $import;
26
    }
27
28
    public function addVue(VueJS $vue):void {
29
        $this->vues[] = $vue;
30
    }
31
32
    public function __toString():string {
33
        $script = implode("\n",$this->imports);
34
        $script .= implode("\n",$this->vues);
35
        return JavascriptUtils::wrapScript($script);
36
    }
37
}