Function divide
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
public function divide()
{
$lines = [];
$line = (new self())
->setDocument($this->document)
- 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 class LineBox has an overall complexity of 67 which is very high. The configured complexity threshold is 50. Open
class LineBox extends Box implements BoxInterface
{
/**
* Append block box element.
*
- Exclude checks
The class LineBox has 14 public methods. Consider refactoring LineBox to keep number of public methods under 10. Open
class LineBox extends Box implements BoxInterface
{
/**
* Append block box element.
*
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
File LineBox.php
has 303 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
/**
* LineBox class.
Function clearStyles
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function clearStyles()
{
$allNestedChildren = [];
$maxLevel = '0';
foreach ($this->getChildren() as $child) {
- 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 divide
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function divide()
{
$lines = [];
$line = (new self())
->setDocument($this->document)
Method clearStyles
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function clearStyles()
{
$allNestedChildren = [];
$maxLevel = '0';
foreach ($this->getChildren() as $child) {
Function getChildrenWidth
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getChildrenWidth()
{
$width = '0';
foreach ($this->getChildren() as $childBox) {
if ($childBox->isForMeasurement()) {
- 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 appendBarcode
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function appendBarcode($childDomElement, $element, $style, $parentBlock)
{
$box = (new BarcodeBox())
->setDocument($this->document)
->setElement($element)
- 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 clearStyles() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function clearStyles()
{
$allNestedChildren = [];
$maxLevel = '0';
foreach ($this->getChildren() as $child) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method divide() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function divide()
{
$lines = [];
$line = (new self())
->setDocument($this->document)
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed. Open
public function clearStyles()
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 40 to the 15 allowed. Open
public function divide()
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The method measureOffset has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation. Open
public function measureOffset(bool $afterPageDividing = 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 measureHeight has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation. Open
public function measureHeight(bool $afterPageDividing = 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 measureWidth has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation. Open
public function measureWidth(bool $afterPageDividing = 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 measurePosition has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation. Open
public function measurePosition(bool $afterPageDividing = 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$childBox->setForMeasurement(true);
}
- 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
Avoid using static access to class '\YetiForcePDF\Math' in method 'getChildrenWidth'. Open
$width = Math::add($width, $childWidth);
- 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 '\YetiForcePDF\Math' in method 'measureOffset'. Open
$top = Math::add($top, $this->getStyle()->getRules('margin-top'));
- 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 '\YetiForcePDF\Math' in method 'measureMargins'. Open
$marginTop = Math::max($marginTop, $child->getStyle()->getRules('margin-top'));
- 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (!$childBox->containContent()) {
// if we doesn't have content and previous element too do not measure me
if ($previous = $children[$index - 1]) {
if (!$previous->containContent()) {
- 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
Avoid assigning values to variables in if clauses and the like (line '231', column '11'). Open
public function divide()
{
$lines = [];
$line = (new self())
->setDocument($this->document)
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '442', column '9'). Open
public function getChildrenWidth()
{
$width = '0';
foreach ($this->getChildren() as $childBox) {
if ($childBox->isForMeasurement()) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\YetiForcePDF\Math' in method 'getChildrenWidth'. Open
$width = Math::add($width, $childBox->getDimensions()->getOuterWidth());
- 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 appendInlineBlock uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$box = (new InlineBlockBox())
->setDocument($this->document)
->setElement($element)
->setParent($this)
- 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
Avoid using static access to class '\YetiForcePDF\Math' in method 'willFit'. Open
return Math::comp(Math::sub($availableSpace, $childrenWidth), $boxWidth) >= 0;
- 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 '\YetiForcePDF\Math' in method 'willFit'. Open
return Math::comp(Math::sub($availableSpace, $childrenWidth), $boxWidth) >= 0;
- 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$childBox->setForMeasurement(true);
}
- 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$childBox->setForMeasurement(true);
}
- 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 getChildrenWidth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$width = Math::add($width, $childBox->getDimensions()->getOuterWidth());
}
- 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$lines[] = $line;
$line = (new self())
->setDocument($this->document)
->setParent($this->getParent())
- 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
Avoid using static access to class '\YetiForcePDF\Math' in method 'measureWidth'. Open
$width = Math::add($width, $child->getDimensions()->getOuterWidth());
- 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 '\YetiForcePDF\Math' in method 'measurePosition'. Open
$this->getCoordinates()->setX(Math::add($parent->getCoordinates()->getX(), $this->getOffset()->getLeft()));
- 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 '\YetiForcePDF\Math' in method 'measurePosition'. Open
$this->getCoordinates()->setY(Math::add($parent->getCoordinates()->getY(), $this->getOffset()->getTop()));
- 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 '\YetiForcePDF\Math' in method 'clearStyles'. Open
$maxLevel = Math::max($maxLevel, (string) \count($allChildren));
- 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 divide uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$childBox->setForMeasurement(true);
}
- 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
Avoid using static access to class '\YetiForcePDF\Math' in method 'measureMargins'. Open
$marginBottom = Math::max($marginBottom, $child->getStyle()->getRules('margin-bottom'));
- 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 '\YetiForcePDF\Math' in method 'measureOffset'. Open
$top = Math::add($previous->getOffset()->getTop(), $previous->getDimensions()->getHeight(), $previous->getStyle()->getRules('margin-bottom'));
- 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
Define a constant instead of duplicating this literal "margin-top" 3 times. Open
$marginTop = Math::max($marginTop, $child->getStyle()->getRules('margin-top'));
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "margin-bottom" 3 times. Open
$marginBottom = Math::max($marginBottom, $child->getStyle()->getRules('margin-bottom'));
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "data-barcode" 3 times. Open
if ($childDomElement->hasAttribute('data-barcode') && $childDomElement->getAttribute('data-barcode')) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "data-height" 3 times. Open
if ($childDomElement->hasAttribute('data-height') && $childDomElement->getAttribute('data-height')) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "data-code" 3 times. Open
if ($childDomElement->hasAttribute('data-code') && $childDomElement->getAttribute('data-code')) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "data-size" 3 times. Open
if ($childDomElement->hasAttribute('data-size') && $childDomElement->getAttribute('data-size')) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid unused parameters such as '$childDomElement'. Open
public function appendInline($childDomElement, $element, $style, $parentBlock)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$parentBlock'. Open
public function appendInlineBlock($childDomElement, $element, $style, $parentBlock)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$parentBlock'. Open
public function appendBarcode($childDomElement, $element, $style, $parentBlock)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function appendInline($childDomElement, $element, $style, $parentBlock)
{
$box = (new InlineBox())
->setDocument($this->document)
->setElement($element)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 90.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
* @param \DOMNode $childDomElement
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Append block box element.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \YetiForcePDF\Layout\BlockBox
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setDocument($this->document)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($childDomElement->hasAttribute('data-barcode') && $childDomElement->getAttribute('data-barcode')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Style $style
- 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
return $parentBlock->appendBlock($childDomElement, $element, $style, $parentBlock);
- 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
* Append table block box element.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Style $style
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($childDomElement->hasAttribute('data-code') && $childDomElement->getAttribute('data-code')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Add inline child (and split text to individual characters).
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Is this line empty? - filled with whitespaces / non measurable elements.
- 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
* Append inline block box element.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\BlockBox|null $parentBlock
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->buildTree($box);
- 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
* Append barcode box element.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \DOMNode $childDomElement
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $box;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->setType($childDomElement->getAttribute('data-barcode'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->setCode($childDomElement->getAttribute('data-code'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->generateBarcodeImage();
- 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
return $box;
- 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
$childrenWidth = $this->getChildrenWidth();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$boxWidth) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Remove white spaces.
- 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
* @param Style $style
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->getStyle()->init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box = (new BarcodeBox())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \DOMNode $childDomElement
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function appendInline($childDomElement, $element, $style, $parentBlock)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this)
- 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
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\BlockBox|null $parentBlock
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \YetiForcePDF\Layout\InlineBlockBox
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($childDomElement->hasAttribute('data-height') && $childDomElement->getAttribute('data-height')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->setHeight($childDomElement->getAttribute('data-height'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->getStyle()->init();
- 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
$boxWidth = $box->getDimensions()->getWidth();
- 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
* @return \YetiForcePDF\Layout\BlockBox
- 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
->setStyle($style)
- 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
* @return \YetiForcePDF\Layout\InlineBlockBox
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Element $element
- 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
->setDocument($this->document)
- 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
$boxWidth = $box->getDimensions()->getOuterWidth();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function removeWhiteSpaces()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Style $style
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Element $element
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \DOMNode $childDomElement
- 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 appendBarcode($childDomElement, $element, $style, $parentBlock)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($childDomElement->hasAttribute('data-size') && $childDomElement->getAttribute('data-size')) {
- 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 appendBlock($childDomElement, $element, $style, $parentBlock)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\BlockBox|null $parentBlock
- 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
$box = (new ImageBox())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->appendChild($box);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \YetiForcePDF\Layout\InlineBox
- 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
return Math::comp(Math::sub($availableSpace, $childrenWidth), $boxWidth) >= 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$childBox->containContent()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- 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($children);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$width = Math::add($width, $child->getDimensions()->getOuterWidth());
- 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
return $parentBlock->appendTableBlock($childDomElement, $element, $style, $parentBlock);
- 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
->setStyle($style, false)
- 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
* @param Element $element
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->getStyle()->init();
- 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
* @return $this
- 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 ($line->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Measure width.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->clearStyles();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->measureWidth($afterPageDividing);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$marginBottom = Math::max($marginBottom, $child->getStyle()->getRules('margin-bottom'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parent = $this->getParent();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Element $element
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \DOMNode $childDomElement
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function appendTableBlock($childDomElement, $element, $style, $parentBlock)
- 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
$box = (new InlineBlockBox())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $box;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->init();
- 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
$box = (new InlineBox())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setElement($element)
- 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
return true;
- 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
* Will this box fit in line? (or need to create new one).
- 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 (!$line->containContent()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $afterPageDividing
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- 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 measureHeight(bool $afterPageDividing = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Measure margins.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\BlockBox|null $parentBlock
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Element $element
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function appendInlineBlock($childDomElement, $element, $style, $parentBlock)
- 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
} else {
- 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
->init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->appendChild($box);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->buildTree($parentBlock);
- 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 willFit(Box $box)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$availableSpace = $this->getDimensions()->computeAvailableSpace();
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// append last line
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lines[] = $line;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($lines as $line) {
- 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
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getAllChildren($allChildren, false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Style $style
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setStyle($style)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->appendChild($box);
- 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
->setElement($element)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$box->buildTree($box);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\BlockBox|null $parentBlock
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setDocument($this->document)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \YetiForcePDF\Layout\Box $box
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($line->willFit($childBox)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(true);
- 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
$line->appendChild($childBox);
- 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 ($child instanceof InlineBlockBox) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $afterPageDividing
- 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 ('img' === $childDomElement->tagName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setElement($element)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setStyle($style)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setDocument($this->document)
- 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 ($child->isForMeasurement() || $child->getStyle()->haveSpacing()) {
- 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
* @return LineBox[]
- 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
$isForMeasurement = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $lines;
- 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
return $this;
- 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
$this->getDimensions()->setHeight('0');
- 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
->setElement($element)
- 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
$box->setSize($childDomElement->getAttribute('data-size'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isEmpty()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// if we doesn't have content and previous element too do not measure me
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$isForMeasurement = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$line->forMeasurement = $isForMeasurement;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->measureHeight($afterPageDividing);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style->setRule('margin-top', $marginTop);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lines = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this->getParent())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$line->appendChild($childBox);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function measureWidth(bool $afterPageDividing = false)
- 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
$marginTop = Math::max($marginTop, $child->getStyle()->getRules('margin-top'));
- 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 ($previous && !$previous->isAbsolute()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getOffset()->setTop($top);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Position.
- 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
$current = $childArray[$row];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($count > 1) {
- 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 ($child->containContent()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->setForMeasurement(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$line = (new self())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setDocument($this->document)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// if this is beginning of the line
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setParent($this->getParent())
- 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
foreach ($this->getChildren() as $child) {
- 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 getInstructions(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return implode("\n", $element);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->iterateChildren(function ($child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$children = $this->getChildren();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setStyle(clone $this->style)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$childBox->containContent()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lineHeight = $this->getStyle()->getMaxLineHeight();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function measureMargins()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$previous = $this->getPrevious();
- 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
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function measurePosition(bool $afterPageDividing = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->isRenderable()) {
- 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 ($cloneArray as $index => $clone) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$clone->getStyle()->clearFirstInline();
- 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 ($childBox->isForMeasurement()) {
- 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
$line = (new self())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setDocument($this->document)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->init();
- 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
return $this;
- 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->getDimensions()->setHeight($lineHeight);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style = $this->getStyle();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$top = $parentStyle->getOffsetTop();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getCoordinates()->setX(Math::add($parent->getCoordinates()->getX(), $this->getOffset()->getLeft()));
- 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 ($allNestedChildren as $childArray) {
- 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
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->setForMeasurement(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}, true, false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($children as $index => $childBox) {
- 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 ($previous = $children[$index - 1]) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lines[] = $line;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$width = '0';
- 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
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function measureOffset(bool $afterPageDividing = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $afterPageDividing
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parent = $this->getParent();
- 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
$clones[$current->getId()][] = $current;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfY = $coordinates->getPdfY();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dimensions = $this->getDimensions();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$width = $dimensions->getWidth();
- 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
if (!$this->isForMeasurement() || $this->isEmpty()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allChildren = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$marginTop = '0';
- Exclude checks
Line exceeds 120 characters; contains 154 characters Open
$top = Math::add($previous->getOffset()->getTop(), $previous->getDimensions()->getHeight(), $previous->getStyle()->getRules('margin-bottom'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function clearStyles()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$clone->getStyle()->clearLastInline();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$clone->getStyle()->clearMiddleInline();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$width = '0';
- 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
* Divide this line into more lines when objects doesn't fit.
- 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
$childBox->setForMeasurement(true);
- 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 ($allChildren as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$maxLevel = Math::max($maxLevel, (string) \count($allChildren));
- 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
* @return string
- 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
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$clones = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($clones as $row => $cloneArray) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get element PDF instructions to use in content stream.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->measureOffset($afterPageDividing);
- 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
$allChildren = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->getAllChildren($allChildren);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($childArray[$row])) {
- 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 children width.
- 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
$top = Math::add($previous->getOffset()->getTop(), $previous->getDimensions()->getHeight(), $previous->getStyle()->getRules('margin-bottom'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$top = Math::add($top, $this->getStyle()->getRules('margin-top'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getOffset()->setLeft($left);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $index) {
- 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
public function divide()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setStyle(clone $this->style)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$childBox->containContent()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$childBox->setForMeasurement(false);
- 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
* @param bool $afterPageDividing
- 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
$marginBottom = '0';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$left = $parentStyle->getOffsetLeft();
- 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->getCoordinates()->setY(Math::add($parent->getCoordinates()->getY(), $this->getOffset()->getTop()));
- 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 ($this->getChildren() as $childBox) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($childWidth = $childBox->getDimensions()->getWidth()) {
- 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
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$child->measurePosition($afterPageDividing);
- 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
* return $this;.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allNestedChildren = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allNestedChildren[] = $allChildren;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
for ($row = 0; $row < $maxLevel; ++$row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$coordinates = $this->getCoordinates();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$height = $dimensions->getHeight();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$element = [];
- 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
* Clear styles
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$maxLevel = '0';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($index === $count - 1) {
- 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
$width = Math::add($width, $childBox->getDimensions()->getOuterWidth());
- 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
$line->appendChild($childBox);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$previous->containContent()) {
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($child->isForMeasurement()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getDimensions()->setWidth($width);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Measure height.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->measureMargins();
- 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
$style->setRule('margin-bottom', $marginBottom);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Position.
- 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 ($this->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->getChildren() as $child) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$count = \count($cloneArray);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($index > 0 && $index < ($count - 1)) {
- 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 getChildrenWidth()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentStyle = $parent->getStyle();
- 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
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$element = $this->addBorderInstructions($element, $pdfX, $pdfY, $width, $height);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$width = Math::add($width, $childWidth);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $width;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfX = $coordinates->getPdfX();
- Exclude checks