Test Failed
Push — main ( 5327e9...2642ec )
by Guillaume
03:06
created

VueJSGlobalComponent::generateGlobalScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
namespace PHPMV;
3
4
use PHPMV\utils\JsUtils;
5
6
class VueJSGlobalComponent extends VueJSComponent {
7
8
    public function generateGlobalScript():string {
9
        $script = "Vue.component('".$this->name."',";
10
        $script .= $this->generateObject();
11
        $script .= ")";
12
        return $script;
13
    }
14
15
    public function generateFile(bool $inVariable = false, bool $global = false):void {
16
        $script = ($inVariable) ? JsUtils::declareVariable("const", $this->varName, $this->generateGlobalScript(), false) : $this->generateGlobalScript().";";
0 ignored issues
show
Bug introduced by
It seems like $this->varName can also be of type null; however, parameter $name of PHPMV\utils\JsUtils::declareVariable() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

16
        $script = ($inVariable) ? JsUtils::declareVariable("const", /** @scrutinizer ignore-type */ $this->varName, $this->generateGlobalScript(), false) : $this->generateGlobalScript().";";
Loading history...
17
        if (!$global){
18
            \file_put_contents($this->name.".js",$script);
19
        }
20
        elseif(file_exists("components.js")){
21
            \file_put_contents("components.js",PHP_EOL . $script,FILE_APPEND);
22
        }
23
        else{
24
            \file_put_contents("components.js",$script);
25
        }
26
    }
27
}