Your project must not contain invalid function or method calls
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- $entityToOverride = $matrixRecord->getEntity();
- return null === $entityToOverride
- ? $criteria
- : $this->addCriteriaToOmitEntity($criteria, $entityToOverride);
- }
- /**
- * @param array<string, array<int, array{0: string, 1: scalar}>> $criteria
- *
Your project should not use invalid return types 5
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_return_typehint
- $data = [];
- foreach ($fields as $field) {
- $data[$field] = $matrixRecord->$field;
- }
- return $data;
- }
- /**
- * @param array<string, scalar> $matrixDataToCompare
- */
- $criteria[ColumnNameHelper::toCamelCase($fieldName)][] = ['=', $value];
- }
- $entityToOverride = $matrixRecord->getEntity();
- return null === $entityToOverride
- ? $criteria
- : $this->addCriteriaToOmitEntity($criteria, $entityToOverride);
- }
- /**
- foreach ($primaryKeyData as $primaryKeyName => $primaryValue) {
- $criteria[$primaryKeyName][] = ['!=', $primaryValue];
- }
- return $criteria;
- }
- /**
- * @param array<string, array<int, array{0: string, 1: scalar}>> $criteria
- */
- /**
- * @phpstan-return non-empty-string
- */
- private function getSeparator(FormFieldDefinition $fieldDefinition): string
- {
- return $fieldDefinition->getOptions()['separator'] ?? ArrayTextType::DEFAULT_SEPARATOR;
- }
- }
- $this->data[$name] = $value;
- }
- public function __get(string $name): int|string|null
- {
- return $this->data[$name];
- }
- }
Your project should not use invalid parameter and return typehints 8
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- }
- /**
- * @return array<string, array<int, array{0: string, 1: scalar}>>
- */
- private function buildCriteria(MatrixRecord $matrixRecord, array $matrixDataToCompare): array
- {
- $criteria = [];
- foreach ($matrixDataToCompare as $fieldName => $value) {
- $criteria[ColumnNameHelper::toCamelCase($fieldName)][] = ['=', $value];
- }
- class MatrixRecord
- {
- private ?object $entity = null;
- private array $data = [];
- public function __construct(array $data = [], public readonly int|string|null $entityId = null)
- {
- foreach ($data as $name => $value) {
- if (!empty(\trim((string) $name))) {
- $this->data[\str_replace(' ', '_', (string) $name)] = $value;
- }
- $container
- ->registerForAutoconfiguration(ImportConfigurationAutoInjectInterface::class)
- ->addTag('batch_entity_import.controller');
- }
- private function setParameters(array $configs, ContainerBuilder $container): void
- {
- $processor = new Processor();
- $configuration = new Configuration();
- $config = $processor->processConfiguration($configuration, $configs);
- $this->addTemplatesConfig($rootNode->children());
- return $treeBuilder;
- }
- private function addTemplatesConfig(NodeBuilder $parentBuilder): void
- {
- $builder = $parentBuilder->arrayNode('templates')->addDefaultsIfNotSet()->children();
- $this->addNodeConfig($builder, 'select_file', '@BatchEntityImport/select_file.html.twig');
- $this->addNodeConfig($builder, 'edit_matrix', '@BatchEntityImport/edit_matrix.html.twig');
- $this->addNodeConfig($builder, 'select_file', '@BatchEntityImport/select_file.html.twig');
- $this->addNodeConfig($builder, 'edit_matrix', '@BatchEntityImport/edit_matrix.html.twig');
- $this->addNodeConfig($builder, 'layout', '@BatchEntityImport/layout.html.twig');
- }
- private function addNodeConfig(NodeBuilder $builder, string $name, string $value): void
- {
- $builder
- ->scalarNode($name)
- ->defaultValue($value)
- ->cannotBeEmpty()
- namespace JG\BatchEntityImportBundle\Model\Form;
- readonly class FormFieldDefinition
- {
- public function __construct(private string $class, private array $options = [])
- {
- }
- public function getClass(): string
- {
- protected function prepareContext(): void
- {
- $this->context->setNode($this->context->getValue(), $this->context->getObject(), $this->context->getMetadata(), '');
- }
- protected function addErrorToMatrixRecord(MatrixRecord $record, MatrixRecordUnique|DatabaseEntityUnique $constraint, int $index, array $fields): void
- {
- $this->context
- ->buildViolation($constraint->message, ['%fields%' => implode(', ', $fields)])
- ->atPath(sprintf('children[records][%d][%s]', $index, $constraint->fields[0]))
- ->setInvalidValue($record)
- ->atPath(sprintf('children[records][%d][%s]', $index, $constraint->fields[0]))
- ->setInvalidValue($record)
- ->addViolation();
- }
- protected function getHash(array $data): string
- {
- return md5(implode('--', $data));
- }
- }
Your project should use return types 6
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.missing_return_typehint
- public function setEntity(?object $entity): void
- {
- $this->entity = $entity;
- }
- public function getData(): array
- {
- return $this->data;
- }
- public function __isset(string $name): bool
- public function getClass(): string
- {
- return $this->class;
- }
- public function getOptions(): array
- {
- return $this->options;
- }
- }
- }
- return implode($this->separator, $value);
- }
- public function reverseTransform(mixed $value): array
- {
- if (!is_string($value)) {
- throw new UnexpectedValueException('Only strings are allowed');
- }
- public function getEntityTranslationRelationName(): ?string;
- /**
- * Use this method to pass constraints to the main Matrix form.
- */
- public function getMatrixConstraints(): array;
- /**
- * Use this method to set allowed file extensions.
- */
- public function getAllowedFileExtensions(): array;
- public function getMatrixConstraints(): array;
- /**
- * Use this method to set allowed file extensions.
- */
- public function getAllowedFileExtensions(): array;
- /**
- * Import data from matrix to database.
- */
- public function import(Matrix $matrix): void;
- }
- /**
- * @param string[] $fieldsUsedInDuplicationCheck
- */
- private function getMatrixRecordDataForDuplicationCheck(MatrixRecord $matrixRecord, array $fieldsUsedInDuplicationCheck): array
- {
- return array_intersect_key($matrixRecord->getData(), array_flip($fieldsUsedInDuplicationCheck));
- }
- }