Method createThumbnail
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function createThumbnail($import, $export, $width, $height, $background, $border)
{
$svg = file_get_contents($import);
$svgObj = simplexml_load_string($svg);
$viewBox = explode(' ', $svgObj['viewBox']);
Method createThumbnail
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private function createThumbnail($import, $export, $width, $height, $background, $border)
Missing class import via use statement (line '65', column '37'). Open
$im->setBackgroundColor(new \ImagickPixel($background));
- 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 '63', column '19'). Open
$im = new \Imagick();
- 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 '\Illuminate\Support\Facades\Artisan' in method 'handle'. Open
Artisan::call('cache:clear');
- 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 method createThumbnail uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$ratio = $height / $viewBoxHeight;
}
- Read upRead up
- Exclude checks
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
The method createThumbnail uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$compensateWidth = $width - ($viewBoxWidth * $ratio);
$im->extentImage($width - $compensateWidth / 2, $height, $compensateWidth * -.5, 0);
$im->extentImage($width, $height, 0, 0);
}
- Read upRead up
- Exclude checks
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
Call to method extentImage
from undeclared class \Imagick
Open
$im->extentImage($width, $height - $compensateHeight / 2, 0, $compensateHeight * -.5);
- Exclude checks
Call to method extentImage
from undeclared class \Imagick
Open
$im->extentImage($width - $compensateWidth / 2, $height, $compensateWidth * -.5, 0);
- Exclude checks
Call to method call
from undeclared class \Illuminate\Support\Facades\Artisan
Open
Artisan::call('cache:clear');
- Exclude checks
Call to method __construct
from undeclared class \ImagickPixel
Open
$im->setBackgroundColor(new \ImagickPixel($background));
- Exclude checks
Call to method inDefaultSite
from undeclared class \Statamic\Globals\GlobalSet
Open
&& $globals->inDefaultSite()->get('use');
- Exclude checks
Call to method readImageBlob
from undeclared class \Imagick
Open
$im->readImageBlob($svg);
- Exclude checks
Call to method getImageBlob
from undeclared class \Imagick
Open
file_put_contents($export, $im->getImageBlob());
- Exclude checks
Parameter $globals
has undeclared type \Statamic\Globals\GlobalSet
Open
private function shouldHandle(GlobalSet $globals)
- Exclude checks
Call to method setBackgroundColor
from undeclared class \Imagick
Open
$im->setBackgroundColor(new \ImagickPixel($background));
- Exclude checks
Reference to constant FILTER_LANCZOS
from undeclared class \Imagick
Open
$im->resizeImage($width, $height, \imagick::FILTER_LANCZOS, 1);
- Exclude checks
Call to method handle
from undeclared class \Statamic\Globals\GlobalSet
Open
return $globals->handle() === 'favicons'
- Exclude checks
Parameter $event
has undeclared type \Statamic\Events\GlobalSetSaved
Open
public function handle(GlobalSetSaved $event)
- Exclude checks
Call to method __construct
from undeclared class \Imagick
Open
$im = new \Imagick();
- Exclude checks
Call to method setResolution
from undeclared class \Imagick
Open
$im->setResolution($viewBoxWidth * $ratio * 2, $viewBoxHeight * $ratio * 2);
- Exclude checks
Call to method extentImage
from undeclared class \Imagick
Open
$im->extentImage($width, $height, 0, 0);
- Exclude checks
Call to method extentImage
from undeclared class \Imagick
Open
$im->extentImage($width, $height, 0, 0);
- Exclude checks
Call to method resizeImage
from undeclared class \Imagick
Open
$im->resizeImage($width, $height, \imagick::FILTER_LANCZOS, 1);
- Exclude checks
Call to method destroy
from undeclared class \Imagick
Open
$im->destroy();
- Exclude checks
Call to method setImageFormat
from undeclared class \Imagick
Open
$im->setImageFormat('png32');
- Exclude checks
Reference to instance property globals
from undeclared class \Statamic\Events\GlobalSetSaved
Open
$globals = $event->globals;
- Exclude checks
Suspicious array access to \SimpleXMLElement|false
Open
$viewBox = explode(' ', $svgObj['viewBox']);
- Exclude checks
Reference to constant FILTER_LANCZOS
from undeclared class \Imagick
Open
$im->resizeImage($viewBoxWidth * $ratio, $viewBoxHeight * $ratio, \imagick::FILTER_LANCZOS, 1);
- Exclude checks
Call to method resizeImage
from undeclared class \Imagick
Open
$im->resizeImage($viewBoxWidth * $ratio, $viewBoxHeight * $ratio, \imagick::FILTER_LANCZOS, 1);
- Exclude checks
Call to method clear
from undeclared class \Imagick
Open
$im->clear();
- Exclude checks
Call to method borderImage
from undeclared class \Imagick
Open
$im->borderImage($background, $border, $border);
- Exclude checks
Avoid variables with short names like $im. Configured minimum length is 3. Open
$im = new \Imagick();
- 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
Opening brace indented incorrectly; expected 4 spaces, found 11 Open
: bool {
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->createThumbnail('favicons/' . $svg, 'favicons/android-chrome-512x512.png', 512, 512, 'transparent',
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->createThumbnail('favicons/' . $svg, 'favicons/android-chrome-512x512.png', 512, 512, 'transparent',
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->createThumbnail('favicons/' . $svg, 'favicons/android-chrome-512x512.png', 512, 512, 'transparent',
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->createThumbnail('favicons/' . $svg, 'favicons/android-chrome-512x512.png', 512, 512, 'transparent',
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
false);
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$this->createThumbnail('favicons/' . $svg, 'favicons/android-chrome-512x512.png', 512, 512, 'transparent',
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 12 Open
false);
- Exclude checks