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;
}
- Read upRead up
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)
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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
- Exclude checks
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);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_StringTemplate
- Exclude checks
The property $_lookfor is not named in camelCase. Open
class Vtiger_StringTemplate
{
// Template variables set dynamically
public $tplvars = [];
- Read upRead up
- Exclude checks
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 = [];
- Read upRead up
- Exclude checks
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 = '/\$([^\$]+)\$/';
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
"/$matchstr_regex/", $replacewith, $instring);
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
"/$matchstr_regex/", $replacewith, $instring);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$restorevars = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$replacewith = $this->get($matchkey);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Template variables set dynamically
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$restorevars[$varkey] = $this->get($varkey);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** Look for variables */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** Replace variables found with value assigned. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Identify variable with the following pattern
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get replacement value for the variable.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->tplvars = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assign($key, $val);
- Exclude checks
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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instring;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $tplvars = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($instring)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = preg_replace('/\//', '\\/', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return preg_replace('/(?<!\\\)\$/', '\\\\$', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* (except the once in the given list).
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($restorevars as $key => $val) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @returns merged contents
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matchstr = $matches[0][$index];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Clean up the input to be used as a regex.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Constructor.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matches = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($this->tplvars[$key])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $this->tplvars[$key];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __formatAsRegex($value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($this->tplvars);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $_lookfor = '/\$([^\$]+)\$/';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matchcount = count($matches[1]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
for ($index = 0; $index < $matchcount; ++$index) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
"/$matchstr_regex/", $replacewith, $instring);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function assign($key, $value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($exceptvars as $varkey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($replacewith && !is_array($replacewith)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function get($key)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function clear($exceptvars = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
preg_match_all($this->_lookfor, $instring, $matches);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instring = preg_replace(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instring;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// If $ is not already escaped as \$ do it now
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->tplvars[$key] = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function merge($instring, $avoidLookup = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$avoidLookup) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matchkey = $matches[1][$index];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// If / is not already escaped as \/ do it now
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Assign replacement value for the variable.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($exceptvars) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* $VARIABLE_KEY$.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Clear all the assigned variable values.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Merge the given file with variable values assigned.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param $instring input string template
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$matchstr_regex = $this->__formatAsRegex($matchstr);
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
"/$matchstr_regex/", $replacewith, $instring);
- Exclude checks
Multi-line function call not indented correctly; expected 20 spaces but found 24 Open
"/$matchstr_regex/", $replacewith, $instring);
- Exclude checks
Class name "Vtiger_StringTemplate" is not in camel caps format Open
class Vtiger_StringTemplate
- Exclude checks
The variable $matchstr_regex is not named in camelCase. Open
public function merge($instring, $avoidLookup = false)
{
if (empty($instring)) {
return $instring;
}
- Read upRead up
- Exclude checks
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;
}
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}