Function saveFileFromDrive
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function saveFileFromDrive($filename, $oauthToken)
{
if ($filename && $oauthToken && $this->has('pointer') &&
(substr(strtolower($this->pointer), 0, 24) === 'https://drive.google.com')
) {
- 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
Function saveFileFromWeb
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function saveFileFromWeb()
{
if ($this->has('thumbnail') &&
(substr(strtolower($this->thumbnail), 0, 7) === 'http://' ||
substr(strtolower($this->thumbnail), 0, 8) === 'https://')
- 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
Method saveFileFromDrive
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function saveFileFromDrive($filename, $oauthToken)
{
if ($filename && $oauthToken && $this->has('pointer') &&
(substr(strtolower($this->pointer), 0, 24) === 'https://drive.google.com')
) {
Method getTag
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getTag($width = null, $height = null, $crop = null, $class = null, $attributes = [], $lazy = false)
Method getLazyTag
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getLazyTag($width = null, $height = null, $crop = null, $class = null, $attributes = [])
Missing class import via use statement (line '106', column '22'). Open
$image = new Ajde_Resource_Image($path);
- Read upRead up
- Exclude checks
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 getTag has a boolean flag argument $lazy, which is a certain sign of a Single Responsibility Principle violation. Open
public function getTag($width = null, $height = null, $crop = null, $class = null, $attributes = [], $lazy = 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
Missing class import via use statement (line '17', column '28'). Open
$this->added = new Ajde_Db_Function('NOW()');
- Read upRead up
- Exclude checks
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 '20', column '27'). Open
$collection = new MediaCollection();
- Read upRead up
- Exclude checks
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 '88', column '54'). Open
$controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:image'));
- Read upRead up
- Exclude checks
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 '76', column '20'). Open
return new Ajde_Resource_Image($path);
- Read upRead up
- Exclude checks
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 '83', column '22'). Open
$image = new Ajde_Resource_Image($path);
- Read upRead up
- Exclude checks
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
Avoid using static access to class 'Ajde_Fs_Find' in method 'afterDelete'. Open
$clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory.Ajde_Resource_Image::$_thumbDir.DS,
pathinfo($this->pointer, PATHINFO_FILENAME).'_*x*.'.pathinfo($this->pointer, PATHINFO_EXTENSION)));
- Read upRead up
- Exclude checks
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 'Ajde_Fs_Find' in method 'afterDelete'. Open
$clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->thumbnail));
- Read upRead up
- Exclude checks
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 'Ajde_Resource_FileIcon' in method 'displayType'. Open
return "<img class='icon' src='".Ajde_Resource_FileIcon::_($extension)."'' />";
- Read upRead up
- Exclude checks
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 'Ajde_Fs_Find' in method 'afterDelete'. Open
$clean = Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->pointer);
- Read upRead up
- Exclude checks
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 'Ajde_Fs_Find' in method 'afterDelete'. Open
$clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory.Ajde_Resource_Image::$_thumbDir.DS,
pathinfo($this->thumbnail, PATHINFO_FILENAME).'_*x*.'.pathinfo($this->thumbnail, PATHINFO_EXTENSION)));
- Read upRead up
- Exclude checks
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 'Ajde_Controller' in method 'getTag'. Open
$controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:image'));
- Read upRead up
- Exclude checks
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 'Ajde_Http_Curl' in method 'saveFileFromDrive'. Open
$curlResult = Ajde_Http_Curl::get($this->pointer, $path, [
'Authorization: Bearer '.$oauthToken,
]);
- Read upRead up
- Exclude checks
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 'Ajde_Http_Curl' in method 'saveFileFromWeb'. Open
$image = Ajde_Http_Curl::get($this->thumbnail);
- Read upRead up
- Exclude checks
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 property $_autoloadParents is not named in camelCase. Open
class MediaModel extends Ajde_Model
{
protected $_autoloadParents = true;
protected $_displayField = 'name';
- 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
Avoid variables with short names like $fh. Configured minimum length is 3. Open
$fh = fopen($path, 'wb');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The property $_displayField is not named in camelCase. Open
class MediaModel extends Ajde_Model
{
protected $_autoloadParents = true;
protected $_displayField = 'name';
- 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;
}