Your project must not contain invalid function or method calls 16
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- {
- $info = [];
- $checker = new PropertyExistenceChecker($className);
- foreach ($this->header as $name) {
- $info[$name] = $checker->propertyExists($name);
- }
- return $info;
- }
- $this->header = $this->clearHeader($header);
- foreach ($recordsData as $data) {
- $clearedData = $this->clearRecordData($data);
- if ($clearedData) {
- $this->records[] = new MatrixRecord($clearedData, $this->getEntityIdValue($data));
- }
- }
- }
- public function getHeader(): array
- public function __construct(array $header = [], array $recordsData = [])
- {
- $this->header = $this->clearHeader($header);
- foreach ($recordsData as $data) {
- $clearedData = $this->clearRecordData($data);
- if ($clearedData) {
- $this->records[] = new MatrixRecord($clearedData, $this->getEntityIdValue($data));
- }
- }
- }
- }
- private function clearHeader(array $header): array
- {
- $header = array_values(
- array_filter($header, $this->isColumnNameValid(...)),
- );
- return \array_map(static fn (string $name): string => \str_replace(' ', '_', $name), $header);
- }
- {
- $header = array_values(
- array_filter($header, $this->isColumnNameValid(...)),
- );
- return \array_map(static fn (string $name): string => \str_replace(' ', '_', $name), $header);
- }
- private function clearRecordData(array $data): array
- {
- return array_filter($data, $this->isColumnNameValid(...), ARRAY_FILTER_USE_KEY);
- $configuration = new Configuration();
- $config = $processor->processConfiguration($configuration, $configs);
- $templates = $config['templates'];
- $container->setParameter('batch_entity_import.templates', $templates);
- $container->setParameter('batch_entity_import.templates.select_file', $templates['select_file']);
- $container->setParameter('batch_entity_import.templates.edit_matrix', $templates['edit_matrix']);
- $container->setParameter('batch_entity_import.templates.layout', $templates['layout']);
- }
- }
- $templates = $config['templates'];
- $container->setParameter('batch_entity_import.templates', $templates);
- $container->setParameter('batch_entity_import.templates.select_file', $templates['select_file']);
- $container->setParameter('batch_entity_import.templates.edit_matrix', $templates['edit_matrix']);
- $container->setParameter('batch_entity_import.templates.layout', $templates['layout']);
- }
- }
- $config = $processor->processConfiguration($configuration, $configs);
- $templates = $config['templates'];
- $container->setParameter('batch_entity_import.templates', $templates);
- $container->setParameter('batch_entity_import.templates.select_file', $templates['select_file']);
- $container->setParameter('batch_entity_import.templates.edit_matrix', $templates['edit_matrix']);
- $container->setParameter('batch_entity_import.templates.layout', $templates['layout']);
- }
- }
- $processor = new Processor();
- $configuration = new Configuration();
- $config = $processor->processConfiguration($configuration, $configs);
- $templates = $config['templates'];
- $container->setParameter('batch_entity_import.templates', $templates);
- $container->setParameter('batch_entity_import.templates.select_file', $templates['select_file']);
- $container->setParameter('batch_entity_import.templates.edit_matrix', $templates['edit_matrix']);
- $container->setParameter('batch_entity_import.templates.layout', $templates['layout']);
- }
- }
- }
- private function parseValueForArrayType(FormFieldDefinition $fieldDefinition, ?string $value): array
- {
- return $value
- ? explode($fieldDefinition->getOptions()['separator'] ?? ArrayTextType::DEFAULT_SEPARATOR, $value)
- : [];
- }
- }
- $setterName = ColumnNameHelper::getSetterName($name);
- if (isset($fieldDefinitions[$name])) {
- $fieldDefinition = $fieldDefinitions[$name];
- if (ArrayTextType::class === $fieldDefinition->getClass()) {
- $value = $this->parseValueForArrayType($fieldDefinition, $value);
- }
- }
- try {
- if (\interface_exists(TranslatableInterface::class) && $entity instanceof TranslatableInterface && $locale) {
- }
- protected function dispatchEvents(): void
- {
- foreach ($this->updatedEntities as $entity) {
- $identifierValues = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
- $this->eventDispatcher->dispatch(
- new RecordImportedSuccessfullyEvent($this->getEntityClassName(), (string) \reset($identifierValues)),
- );
- }
- }
- try {
- if (\interface_exists(TranslatableInterface::class) && $entity instanceof TranslatableInterface && $locale) {
- $translatedEntity = $entity->translate($locale, false);
- if (method_exists($translatedEntity, $setterName)) {
- $translatedEntity->$setterName($value);
- } else {
- $translatedEntity->$propertyName = $value;
- }
- } elseif (!$locale) {
- #[Assert\Callback]
- public function validateExtensions(ExecutionContextInterface $context): void
- {
- $extensions = array_map(strtolower(...), $this->allowedExtensions);
- if (!in_array(strtolower($this->file->getClientOriginalExtension()), $extensions, true)) {
- $context->buildViolation('validation.file.extension', ['%extensions' => implode(', ', $extensions)])->addViolation();
- }
- }
- }
- );
- }
- private function getMatrixRecordDataForDuplicationCheck(MatrixRecord $matrixRecord, array $fieldsUsedInDuplicationCheck): array
- {
- return array_intersect_key($matrixRecord->getData(), array_flip($fieldsUsedInDuplicationCheck));
- }
- }
- }
- private function getHashedMatrixRecordsDataForDuplicationCheck(array $records, array $fieldsUsedInDuplicationCheck): array
- {
- return array_map(
- fn (MatrixRecord $record): string => $this->getHash($this->getMatrixRecordDataForDuplicationCheck($record, $fieldsUsedInDuplicationCheck)),
- $records
- );
- }
- private function getMatrixRecordDataForDuplicationCheck(MatrixRecord $matrixRecord, array $fieldsUsedInDuplicationCheck): array
Your project should use return types 4
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.missing_return_typehint
- }
- return null;
- }
- private function clearHeader(array $header): array
- {
- $header = array_values(
- array_filter($header, $this->isColumnNameValid(...)),
- );
- public function allowOverrideEntity(): bool
- {
- return true;
- }
- public function getAllowedFileExtensions(): array
- {
- return ['csv', 'xls', 'xlsx', 'ods'];
- }
- private function parseValueForArrayType(FormFieldDefinition $fieldDefinition, ?string $value): array
- public function getEntityTranslationRelationName(): ?string
- {
- return null;
- }
- public function getMatrixConstraints(): array
- {
- return [];
- }
- public function import(Matrix $matrix): void
- }
- parent::validateArguments($value, $constraint);
- }
- private function getHashedMatrixRecordsDataForDuplicationCheck(array $records, array $fieldsUsedInDuplicationCheck): array
- {
- return array_map(
- fn (MatrixRecord $record): string => $this->getHash($this->getMatrixRecordDataForDuplicationCheck($record, $fieldsUsedInDuplicationCheck)),
- $records
- );
Your project should not use invalid parameter and return typehints 6
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- new Assert\Type(MatrixRecord::class),
- ])]
- #[Assert\NotBlank]
- private array $records = [];
- public function __construct(array $header = [], array $recordsData = [])
- {
- $this->header = $this->clearHeader($header);
- foreach ($recordsData as $data) {
- $clearedData = $this->clearRecordData($data);
- }
- return null;
- }
- private function clearHeader(array $header): array
- {
- $header = array_values(
- array_filter($header, $this->isColumnNameValid(...)),
- );
- new Assert\Type(MatrixRecord::class),
- ])]
- #[Assert\NotBlank]
- private array $records = [];
- public function __construct(array $header = [], array $recordsData = [])
- {
- $this->header = $this->clearHeader($header);
- foreach ($recordsData as $data) {
- $clearedData = $this->clearRecordData($data);
- }
- return $info;
- }
- private function getEntityIdValue(array $data): int|string|null
- {
- foreach ($data as $name => $value) {
- if (self::RESERVED_ENTITY_ID_COLUMN_NAME === $name) {
- return $value;
- }
- fn (MatrixRecord $record): string => $this->getHash($this->getMatrixRecordDataForDuplicationCheck($record, $fieldsUsedInDuplicationCheck)),
- $records
- );
- }
- private function getMatrixRecordDataForDuplicationCheck(MatrixRecord $matrixRecord, array $fieldsUsedInDuplicationCheck): array
- {
- return array_intersect_key($matrixRecord->getData(), array_flip($fieldsUsedInDuplicationCheck));
- }
- }
- }
- parent::validateArguments($value, $constraint);
- }
- private function getHashedMatrixRecordsDataForDuplicationCheck(array $records, array $fieldsUsedInDuplicationCheck): array
- {
- return array_map(
- fn (MatrixRecord $record): string => $this->getHash($this->getMatrixRecordDataForDuplicationCheck($record, $fieldsUsedInDuplicationCheck)),
- $records
- );
Your project should not use invalid return types
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_return_typehint
- private function getEntityIdValue(array $data): int|string|null
- {
- foreach ($data as $name => $value) {
- if (self::RESERVED_ENTITY_ID_COLUMN_NAME === $name) {
- return $value;
- }
- }
- return null;
- }
Your project must not contain invalid instantiations
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- $data = $spreadsheet->getActiveSheet()->toArray();
- $header = array_shift($data);
- self::addKeysToRows($header, $data);
- return new Matrix($header, $data);
- }
- public static function createFromPostData(array $data): Matrix
- {
- return $data ? new Matrix(array_keys($data[0]), $data) : new Matrix();