Showing 579 of 579 total issues
Method getFieldDescriptor
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getFieldDescriptor(SchemaId $schemaId, array $field)
{
// force default type to be "string"
if (!isset($field['type'])) {
$field['type'] = 'string';
Method loadFile
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function loadFile($file, $schemaOrCallable = null)
{
$content = @file_get_contents($file);
if ('' === trim($content)) {
throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
Method generateMessage
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function generateMessage(SchemaDescriptor $schema, GeneratorResponse $response)
{
$className = $this->schemaToClassName($schema, true);
$psr = $this->schemaToNativeNamespace($schema);
$file = str_replace('\\', '/', "{$psr}\\{$className}");
Method generateMessage
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function generateMessage(SchemaDescriptor $schema, GeneratorResponse $response)
{
$id = $schema->getId();
$className = $this->schemaToClassName($schema, true);
$file = "{$id->getVendor()}/{$id->getPackage()}";
Method getSchemas
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSchemas()
{
return [
[
'data' => __DIR__ . '/Fixtures/json-schema/article.json',
Method convertDomElementToArray
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function convertDomElementToArray(\DomElement $element, $checkPrefix = true)
{
$prefix = (string)$element->prefix;
$empty = true;
$config = [];
Method execute
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$file = $input->getOption('config') ?: sprintf('%s/pbjc.yml', getcwd());
Method fromFile
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function fromFile($file)
{
/** @var \DOMDocument $xmlDomDocument */
if (!$xmlDomDocument = XmlUtils::loadFile($file, __DIR__ . '/../xsd/enums.xsd')) {
throw new \RuntimeException(sprintf(
Function getFieldDescriptor
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function getFieldDescriptor(SchemaId $schemaId, array $field)
{
// force default type to be "string"
if (!isset($field['type'])) {
$field['type'] = 'string';
- 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 __construct
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($id, array $parameters = [])
{
$this->id = $id instanceof SchemaId ? $id : SchemaId::fromString($id);
foreach ($parameters as $key => $value) {
- 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 run
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function run($language, CompileOptions $options)
{
$namespaces = $options->getNamespaces();
if (!$namespaces || count($namespaces) === 0) {
Method setUp
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setUp()
{
SchemaStore::addSchema(
SchemaId::fromString('pbj:vendor2:package2:category2:message2:1-0-0'),
new SchemaDescriptor(
Identical blocks of code found in 2 locations. Consider refactoring. Open
private function getLanguageOptions(array $data)
{
$options = new LanguageBag();
foreach ($data as $key => $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 111.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
private function getLanguageOptions(array $data)
{
$options = new LanguageBag();
foreach ($data as $key => $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 111.
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
The class FieldDescriptor has 20 fields. Consider redesigning FieldDescriptor to keep the number of fields under 15. Open
final class FieldDescriptor
{
/**
* Regular expression pattern for matching a valid field name. The pattern allows
* for camelCase fields name but snake_case is recommend.
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Method validate
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validate(SchemaDescriptor $a, SchemaDescriptor $b)
{
$fa = array_merge($a->getInheritedFields(), $a->getFields());
$fb = array_merge($b->getInheritedFields(), $b->getFields());
Method render
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function render($template, array $parameters)
{
return str_replace(
[
' ',
Function fromFile
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function fromFile($file)
{
/** @var \DOMDocument $xmlDomDocument */
if (!$xmlDomDocument = XmlUtils::loadFile($file, __DIR__ . '/../xsd/enums.xsd')) {
throw new \RuntimeException(sprintf(
- 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 updateFieldOptions
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function updateFieldOptions(SchemaDescriptor $schema, FieldDescriptor $field)
{
if ($enum = $field->getEnum()) {
if (null === $field->getLanguage(static::LANGUAGE)->get('default', null)) {
$default = $field->getDefault();
- 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 updateFieldOptions
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function updateFieldOptions(SchemaDescriptor $schema, FieldDescriptor $field)
{
if ($enum = $field->getEnum()) {
if (null === $field->getLanguage(static::LANGUAGE)->get('default', null)) {
$default = $field->getDefault();
- 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"