YetiForceCompany/YetiForceCRM

View on GitHub
vtlib/Vtiger/Utils/StringTemplate.php

Summary

Maintainability
A
45 mins
Test Coverage
F
5%

Function merge has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function merge($instring, $avoidLookup = false)
    {
        if (empty($instring)) {
            return $instring;
        }
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

    public function merge($instring, $avoidLookup = false)
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.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

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

    public function clear($exceptvars = false)
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.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

Saw misspelled annotation @returns. Did you mean @return?
Open

     * @returns merged contents

Suspicious attempt to unset class \Vtiger_StringTemplate's property tplvars declared at /code/vtlib/Vtiger/Utils/StringTemplate.php:20 (This can be done, but is more commonly done for dynamic properties and Phan does not expect this)
Open

        unset($this->tplvars);

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Vtiger_StringTemplate

The property $_lookfor is not named in camelCase.
Open

class Vtiger_StringTemplate
{
    // Template variables set dynamically
    public $tplvars = [];

Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The class Vtiger_StringTemplate is not named in CamelCase.
Open

class Vtiger_StringTemplate
{
    // Template variables set dynamically
    public $tplvars = [];

Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php by phpmd

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Property name "$_lookfor" should not be prefixed with an underscore to indicate visibility
Open

    public $_lookfor = '/\$([^\$]+)\$/';

Only one argument is allowed per line in a multi-line function call
Open

                        "/$matchstr_regex/", $replacewith, $instring);

Only one argument is allowed per line in a multi-line function call
Open

                        "/$matchstr_regex/", $replacewith, $instring);

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

        $restorevars = [];

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

    /**

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

                $replacewith = $this->get($matchkey);

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

    // Template variables set dynamically

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

                $restorevars[$varkey] = $this->get($varkey);

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

    }

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

            /** Look for variables */

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

            /** Replace variables found with value assigned. */

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

     */

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

     * Identify variable with the following pattern

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 replacement value for the variable.

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

        $this->tplvars = [];

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

            $this->assign($key, $val);

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

     * @param $avoidLookup should be true if only verbatim file copy needs to be done

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

            return $instring;

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 $tplvars = [];

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 (empty($instring)) {

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

        $value = preg_replace('/\//', '\\/', $value);

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

        return preg_replace('/(?<!\\\)\$/', '\\\\$', $value);

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

    {

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

     * (except the once in the given list).

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

        foreach ($restorevars as $key => $val) {

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

     * @returns merged contents

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

                $matchstr = $matches[0][$index];

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

     * Clean up the input to be used as a regex.

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

    {

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

     * Constructor.

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

            $matches = [];

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 (isset($this->tplvars[$key])) {

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

            $value = $this->tplvars[$key];

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 __formatAsRegex($value)

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

     */

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

        unset($this->tplvars);

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

    public $_lookfor = '/\$([^\$]+)\$/';

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

    }

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

            $matchcount = count($matches[1]);

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

            for ($index = 0; $index < $matchcount; ++$index) {

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

                        "/$matchstr_regex/", $replacewith, $instring);

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 assign($key, $value)

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

            foreach ($exceptvars as $varkey) {

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

                if ($replacewith && !is_array($replacewith)) {

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 get($key)

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

    public function clear($exceptvars = false)

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

            preg_match_all($this->_lookfor, $instring, $matches);

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

                    $instring = preg_replace(

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

        return $instring;

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

        // If $ is not already escaped as \$ do it now

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

    public function __construct()

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

    }

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

        $this->tplvars[$key] = $value;

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

    public function merge($instring, $avoidLookup = false)

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

        if (!$avoidLookup) {

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

                $matchkey = $matches[1][$index];

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

        // If / is not already escaped as \/ do it now

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

     * Assign replacement value for the variable.

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

        if ($exceptvars) {

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

            }

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

     * $VARIABLE_KEY$.

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

    /**

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

        $value = false;

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

        return $value;

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

     * Clear all the assigned variable values.

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

        }

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

     * Merge the given file with variable values assigned.

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

     * @param $instring    input string template

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

                $matchstr_regex = $this->__formatAsRegex($matchstr);

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                        "/$matchstr_regex/", $replacewith, $instring);

Multi-line function call not indented correctly; expected 20 spaces but found 24
Open

                        "/$matchstr_regex/", $replacewith, $instring);

Class name "Vtiger_StringTemplate" is not in camel caps format
Open

class Vtiger_StringTemplate

The variable $matchstr_regex is not named in camelCase.
Open

    public function merge($instring, $avoidLookup = false)
    {
        if (empty($instring)) {
            return $instring;
        }
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $matchstr_regex is not named in camelCase.
Open

    public function merge($instring, $avoidLookup = false)
    {
        if (empty($instring)) {
            return $instring;
        }
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The method __formatAsRegex is not named in camelCase.
Open

    public function __formatAsRegex($value)
    {
        // If / is not already escaped as \/ do it now
        $value = preg_replace('/\//', '\\/', $value);
        // If $ is not already escaped as \$ do it now
Severity: Minor
Found in vtlib/Vtiger/Utils/StringTemplate.php by phpmd

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

There are no issues that match your filters.

Category
Status