Showing 77 of 77 total issues
Method xmlEscape
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function xmlEscape(string $str): string
{
// array used to figure what number to decrement from character order value
// according to number of characters used to map unicode to ascii by utf-8
$decrement = [];
Function buildSchema
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function buildSchema(Schema $schema): array
{
$properties = [];
if ($this->getPathDepth() > static::MAX_PATH_DEPTH) {
- 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
FieldBuilder
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
final class FieldBuilder
{
private string $name;
private Type $type;
private ?FieldRule $rule = null;
Method __construct
has 18 arguments (exceeds 4 allowed). Consider refactoring. Open
string $name,
Type $type,
FieldRule $rule,
bool $required = false,
?int $minLength = null,
Function validate
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
final public function validate(bool $strict = false, bool $recursive = false): static
{
if (!$strict && $this->isFrozen()) {
return $this;
}
- 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 doDeserialize
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function doDeserialize(array $data): Message
{
$schemaId = SchemaId::fromString((string)$data[Schema::PBJ_FIELD_NAME]);
$className = MessageResolver::resolveId($schemaId);
$message = new $className();
Method doUnmarshal
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function doUnmarshal(array $data): Message
{
$schemaId = SchemaId::fromString((string)$data[Schema::PBJ_FIELD_NAME]);
$className = MessageResolver::resolveId($schemaId);
$message = new $className();
MappingBuilder
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
class MappingBuilder
{
/**
* Generally we use "__" to indicate a derived field but kibana won't recognize it.
* So for now, we'll use "d__" to indicate a derived field for ES.
Schema
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
final class Schema implements \JsonSerializable
{
const PBJ_FIELD_NAME = '_schema';
private string $className;
Function guard
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function guard(mixed $value, Field $field): void
{
$fieldName = $field->getName();
Assertion::string($value, null, $fieldName);
- 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
Consider simplifying this complex logical expression. Open
} else if (($c >= 8219 && $c <= 8223) || $c == 8242 || $c == 8243 || $c == 8216 || $c == 8217 || $c == 168 || $c == 180 || $c == 729 || $c == 733) {
//all the strange curly single and double quotes
// Ignore them
} else if ($c == 188) {
$slug .= '-one-quarter-';
Function applyDefault
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private function applyDefault($default = null): void
{
$this->default = $default;
if ($this->type->isScalar()) {
- 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 buildSchema
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function buildSchema(Schema $schema): array
{
$properties = [];
if ($this->getPathDepth() > static::MAX_PATH_DEPTH) {
Function encodeValue
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function encodeValue(mixed $value, Field $field): array
{
$type = $field->getType();
if ($type->encodesToScalar()) {
- 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 marshal
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function marshal(Message $message): array
{
$schema = $message::schema();
$message->validate();
$payload = [];
- 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 getNestedMessages
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function getNestedMessages(): array
{
$messages = [];
foreach (static::schema()->getFields() as $field) {
if ($field->getType()->isMessage()) {
- 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 marshal
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function marshal(Message $message): array
{
$schema = $message::schema();
$message->validate();
$payload = [];
Method create
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function create(string $str, bool $camelize = true): ?string
{
// remove special chars (accents, etc.)
$str = trim(self::normalize($str));
$str = ltrim($str, '#_ ');
Method applyDefault
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function applyDefault($default = null): void
{
$this->default = $default;
if ($this->type->isScalar()) {
Identical blocks of code found in 2 locations. Consider refactoring. Open
public function decode(mixed $value, Field $field, ?Codec $codec = null): BigInteger|string|null
{
if (null === $value || $value instanceof BigInteger) {
return $value;
}
- 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 102.
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