YetiForceCompany/YetiForceCRM

View on GitHub
app/SystemWarnings/Template.php

Summary

Maintainability
A
0 mins
Test Coverage
F
22%

Missing class import via use statement (line '190', column '19').
Open

        $refClass = new \ReflectionClass($this);
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '145', column '19').
Open

        $refClass = new \ReflectionClass($this);
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

The method getFolder has a boolean flag argument $toArray, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getFolder($toArray = true)
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Avoid using static access to class '\App\Cache' in method 'update'.
Open

        \App\Cache::resetFileCache($filePath);
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\App\Language' in method 'update'.
Open

        return ['result' => true, 'message' => \App\Language::translate('LBL_DATA_SAVE_OK', 'Settings::SystemWarnings')];
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\App\Layout' in method 'getTpl'.
Open

        $path = \App\Layout::getTemplatePath("{$this->getFolder(false)}/{$className}.tpl", 'Settings:SystemWarnings');
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method update uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $replacement = '{' . PHP_EOL . '    protected $statusValue = ' . $statusValue . ';';
            $fileContent = preg_replace('/{/', $replacement, $fileContent, 1);
        }
Severity: Minor
Found in app/SystemWarnings/Template.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Rename "$statusValue" which has the same name as the field declared at line 27.
Open

        $statusValue = '2' === $params ? 0 : 2;
Severity: Major
Found in app/SystemWarnings/Template.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Argument 1 (haystack) is array<int></int> but \strpos() takes string
Open

        if ($toArray && false !== strpos($this->folder, '\\')) {
Severity: Minor
Found in app/SystemWarnings/Template.php by phan

Argument 2 (str) is array<int></int> but \explode() takes string
Open

            $this->folder = explode('\\', $this->folder);
Severity: Minor
Found in app/SystemWarnings/Template.php by phan

Returning type array{result:true,message:string} but update() is declared to return bool
Open

        return ['result' => true, 'message' => \App\Language::translate('LBL_DATA_SAVE_OK', 'Settings::SystemWarnings')];
Severity: Minor
Found in app/SystemWarnings/Template.php by phan

Returning type array<int></int> but getFolder() is declared to return string
Open

        return $this->folder;
Severity: Minor
Found in app/SystemWarnings/Template.php by phan

Assigning string to property but \App\SystemWarnings\Template->tpl is bool|false
Open

        $this->tpl = $path;
Severity: Minor
Found in app/SystemWarnings/Template.php by phan

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string|null Modal description */

Spaces must be used to indent lines; tabs are not allowed
Open

     * 0 - active, 2 - ignored.

Spaces must be used to indent lines; tabs are not allowed
Open

     * @var int

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string Modal header title */

Spaces must be used to indent lines; tabs are not allowed
Open

     * Status value

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $title;

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var int Warning priority code */

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $priority = 0;

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $statusValue = 0;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $description;

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var bool Template flag */

Spaces must be used to indent lines; tabs are not allowed
Open

        return true;

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->color;

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning link.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!$this->tpl || \is_string($this->tpl)) {

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

            $pattern = '/\$statusValue = ([^;]+)/';

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $link;

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string|null

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public function setFolder($folder)

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $folder;

Spaces must be used to indent lines; tabs are not allowed
Open

    public function preProcess(): bool

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->status;

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->description;

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->link;

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param mixed $toArray

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param mixed $folder

Spaces must be used to indent lines; tabs are not allowed
Open

            $fileContent = preg_replace($pattern, $replacement, $fileContent);

Spaces must be used to indent lines; tabs are not allowed
Open

        } else {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return bool

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->statusValue;

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->folder;

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        $statusValue = '2' === $params ? 0 : 2;

Spaces must be used to indent lines; tabs are not allowed
Open

        $refClass = new \ReflectionClass($this);

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $color;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getColor(): string

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning description.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * Whether a warning is active.

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getPriority(): int

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning title.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getDescription(): ?string

Spaces must be used to indent lines; tabs are not allowed
Open

        $path = \App\Layout::getTemplatePath("{$this->getFolder(false)}/{$className}.tpl", 'Settings:SystemWarnings');

Spaces must be used to indent lines; tabs are not allowed
Open

        return $path;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public function update($params)

Spaces must be used to indent lines; tabs are not allowed
Open

        if (false !== strpos($fileContent, 'protected $statusValue ')) {

Line exceeds 120 characters; contains 121 characters
Open

        return ['result' => true, 'message' => \App\Language::translate('LBL_DATA_SAVE_OK', 'Settings::SystemWarnings')];

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return void

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return int

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string

Spaces must be used to indent lines; tabs are not allowed
Open

            $replacement = '{' . PHP_EOL . '    protected $statusValue = ' . $statusValue . ';';

Spaces must be used to indent lines; tabs are not allowed
Open

        \App\Cache::resetFileCache($filePath);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Status

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning priority.

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->title;

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning status.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        $className = $refClass->getShortName();

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    abstract public function process(): void;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $refClass = new \ReflectionClass($this);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning folder.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            $replacement = '$statusValue = ' . $statusValue;

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getStatusValue(): int

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            return $this->tpl;

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        $filePath = $refClass->getFileName();

Spaces must be used to indent lines; tabs are not allowed
Open

            $fileContent = preg_replace('/{/', $replacement, $fileContent, 1);

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string|null Link URL */

Spaces must be used to indent lines; tabs are not allowed
Open

     * Checking whether there is a warning.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get status value.

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string|null

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getLink(): ?string

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getFolder($toArray = true)

Spaces must be used to indent lines; tabs are not allowed
Open

            $this->folder = explode('\\', $this->folder);

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return bool

Spaces must be used to indent lines; tabs are not allowed
Open

        file_put_contents($filePath, $fileContent);

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $status = 0;

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return int

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($toArray && false !== strpos($this->folder, '\\')) {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->priority;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getStatus()

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getTpl()

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->folder = $folder;

Spaces must be used to indent lines; tabs are not allowed
Open

     * Update ignoring status.

Spaces must be used to indent lines; tabs are not allowed
Open

        return ['result' => true, 'message' => \App\Language::translate('LBL_DATA_SAVE_OK', 'Settings::SystemWarnings')];

Spaces must be used to indent lines; tabs are not allowed
Open

     * @var int

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $tpl = false;

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getTitle(): string

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->tpl = $path;

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int $params

Spaces must be used to indent lines; tabs are not allowed
Open

     * 0 - warning occurred, 1 - no warning.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * Returns the warning color.

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return int

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * Updates the warning folder.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        $fileContent = file_get_contents($filePath);

There are no issues that match your filters.

Category
Status