Method certificateFileResponse
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function certificateFileResponse(
Certificate $certificate,
bool $add_watermark = false,
Watermark $watermark = null
): ResponseInterface {
Function certificateFileResponse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function certificateFileResponse(
Certificate $certificate,
bool $add_watermark = false,
Watermark $watermark = null
): ResponseInterface {
- 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 mediaFileThumbnailResponse
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
MediaFile $media_file,
int $width,
int $height,
string $fit,
bool $add_watermark
Avoid too many return
statements within this method. Open
return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR)
->withHeader('X-Image-Exception', $ex->getMessage());
The class CertificateImageFactory has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13. Open
class CertificateImageFactory extends ImageFactory implements ImageFactoryInterface
{
/**
* @var CertificateFilesystemService $filesystem_service
*/
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method certificateFileResponse has a boolean flag argument $add_watermark, which is a certain sign of a Single Responsibility Principle violation. Open
bool $add_watermark = 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
Avoid using static access to class '\Fisharebest\Webtrees\Auth' in method 'certificateNeedsWatermark'. Open
return Auth::accessLevel($tree, $user) > $watermark_level;
- 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();
}
}