Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/AnnotationGenerator/PhpDocAnnotationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function generateInterfaceAnnotations(Class_ $class): array
public function generateConstantAnnotations(Constant $constant): array
{
$annotations = $this->formatDoc($constant->comment(), true);
$annotations[0] = sprintf('@var string %s', $this->escapePhpDoc($annotations[0]));
$annotations[0] = \sprintf('@var string %s', $this->escapePhpDoc($annotations[0]));

return $annotations;
}
Expand All @@ -62,14 +62,14 @@ public function generatePropertyAnnotations(Property $property, string $classNam

$annotations = [];
if ($this->isDocUseful($property) && $phpDocType = $this->toPhpDocType($property)) {
$annotations[] = sprintf('@var %s %s', $phpDocType, $this->escapePhpDoc($description[0]));
$annotations[] = \sprintf('@var %s %s', $phpDocType, $this->escapePhpDoc($description[0]));
} else {
$annotations = $description;
$annotations[] = '';
}

if (null !== $property->rdfType()) {
$annotations[] = sprintf('@see %s', $property->rdfType());
$annotations[] = \sprintf('@see %s', $property->rdfType());
}

$annotations[] = '';
Expand All @@ -83,7 +83,7 @@ public function generateGetterAnnotations(Property $property): array
return [];
}

return [sprintf('@return %s', $this->toPhpDocType($property))];
return [\sprintf('@return %s', $this->toPhpDocType($property))];
}

public function generateSetterAnnotations(Property $property): array
Expand All @@ -92,7 +92,7 @@ public function generateSetterAnnotations(Property $property): array
return [];
}

return [sprintf('@param %s $%s', $this->toPhpDocType($property), $property->name())];
return [\sprintf('@param %s $%s', $this->toPhpDocType($property), $property->name())];
}

public function generateAdderAnnotations(Property $property): array
Expand All @@ -101,7 +101,7 @@ public function generateAdderAnnotations(Property $property): array
return [];
}

return [sprintf('@param %s $%s', $this->toPhpDocType($property, true), $this->inflector->singularize($property->name())[0])];
return [\sprintf('@param %s $%s', $this->toPhpDocType($property, true), $this->inflector->singularize($property->name())[0])];
}

public function generateRemoverAnnotations(Property $property): array
Expand All @@ -110,7 +110,7 @@ public function generateRemoverAnnotations(Property $property): array
return [];
}

return [sprintf('@param %s $%s', $this->toPhpDocType($property, true), $this->inflector->singularize($property->name())[0])];
return [\sprintf('@param %s $%s', $this->toPhpDocType($property, true), $this->inflector->singularize($property->name())[0])];
}

private function isDocUseful(Property $property, bool $adderOrRemover = false): bool
Expand Down Expand Up @@ -138,12 +138,12 @@ private function generateDoc(Class_ $class, bool $interface = false): array
$annotations[] = '';
}
if ($class->rdfType()) {
$annotations[] = sprintf('@see %s', $class->rdfType());
$annotations[] = \sprintf('@see %s', $class->rdfType());
}
}

if ($this->config['author']) {
$annotations[] = sprintf('@author %s', $this->config['author']);
$annotations[] = \sprintf('@author %s', $this->config['author']);
}

return $annotations;
Expand Down Expand Up @@ -197,10 +197,10 @@ protected function toPhpDocType(Property $property, bool $adderOrRemover = false
}

if ($this->config['doctrine']['useCollection']) {
return sprintf('Collection<%s>%s', $phpDocType, $suffix);
return \sprintf('Collection<%s>%s', $phpDocType, $suffix);
}

return sprintf('%s[]%s', $phpDocType, $suffix);
return \sprintf('%s[]%s', $phpDocType, $suffix);
}

private function escapePhpDoc(string $text): string
Expand Down
4 changes: 2 additions & 2 deletions src/AttributeGenerator/ApiPlatformCoreAttributeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function generateClassAttributes(Class_ $class): array
}
$targetArguments[$method] = $methodArguments;
}
$arguments[sprintf('%sOperations', $operationTarget)] = $targetArguments;
$arguments[\sprintf('%sOperations', $operationTarget)] = $targetArguments;
}
} else {
$arguments['operations'] = [];
Expand All @@ -85,7 +85,7 @@ public function generateClassAttributes(Class_ $class): array
unset($methodConfig['class']);
}

$arguments['operations'][] = new Literal(sprintf('new %s(...?:)',
$arguments['operations'][] = new Literal(\sprintf('new %s(...?:)',
$operationMetadataClass,
), [$methodConfig ?? []]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/AttributeGenerator/ConstraintAttributeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function generatePropertyAttributes(Property $property, string $className
}

if ($property->isEnum && $property->reference) {
$args = ['callback' => [new Literal(sprintf('%s::class', $property->reference->name())), 'toArray']];
$args = ['callback' => [new Literal(\sprintf('%s::class', $property->reference->name())), 'toArray']];

if ($property->isArray()) {
$args['multiple'] = true;
Expand All @@ -96,7 +96,7 @@ public function generateUses(Class_ $class): array
$enumName = $property->reference->name();
$enumClass = $this->classes[$enumName];
$enumNamespace = $enumClass->namespace ?? $this->config['namespaces']['enum'];
$use = new Use_(sprintf('%s\%s', $enumNamespace, $enumName));
$use = new Use_(\sprintf('%s\%s', $enumNamespace, $enumName));

if (!\in_array($use, $uses, true)) {
$uses[] = $use;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function generateClassAttributes(Class_ $class): array
$attributes[] = new Attribute('MongoDB\Document');
$attributes[] = new Attribute('MongoDB\InheritanceType', [\in_array($this->config['doctrine']['inheritanceType'], ['SINGLE_COLLECTION', 'COLLECTION_PER_CLASS', 'NONE'], true) ? $this->config['doctrine']['inheritanceType'] : 'SINGLE_COLLECTION']);
$attributes[] = new Attribute('MongoDB\DiscriminatorField', ['discr']);
$attributes[] = new Attribute('MongoDB\DiscriminatorMap', [array_reduce($mapNames, fn (array $map, string $mapName) => $map + [u($mapName)->camel()->toString() => new Literal(sprintf('%s::class', $mapName))], [])]);
$attributes[] = new Attribute('MongoDB\DiscriminatorMap', [array_reduce($mapNames, fn (array $map, string $mapName) => $map + [u($mapName)->camel()->toString() => new Literal(\sprintf('%s::class', $mapName))], [])]);
} else {
$attributes[] = new Attribute('MongoDB\Document');
}
Expand Down
14 changes: 7 additions & 7 deletions src/AttributeGenerator/DoctrineOrmAttributeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function generateClassAttributes(Class_ $class): array
$attributes[] = new Attribute('ORM\Entity');
$attributes[] = new Attribute('ORM\InheritanceType', [\in_array($this->config['doctrine']['inheritanceType'], ['JOINED', 'SINGLE_TABLE', 'TABLE_PER_CLASS', 'NONE'], true) ? $this->config['doctrine']['inheritanceType'] : 'JOINED']);
$attributes[] = new Attribute('ORM\DiscriminatorColumn', ['name' => 'discr']);
$attributes[] = new Attribute('ORM\DiscriminatorMap', [array_reduce($mapNames, fn (array $map, string $mapName) => $map + [u($mapName)->camel()->toString() => new Literal(sprintf('%s::class', $mapName))], [])]);
$attributes[] = new Attribute('ORM\DiscriminatorMap', [array_reduce($mapNames, fn (array $map, string $mapName) => $map + [u($mapName)->camel()->toString() => new Literal(\sprintf('%s::class', $mapName))], [])]);
} else {
$attributes[] = new Attribute('ORM\Entity');
}
Expand All @@ -79,7 +79,7 @@ public function generateClassAttributes(Class_ $class): array
continue;
}

$attributes[] = new Attribute('ORM\Table', ['name' => sprintf('`%s`', $this->generateIdentifierName($class->name(), 'table', $this->config))]);
$attributes[] = new Attribute('ORM\Table', ['name' => \sprintf('`%s`', $this->generateIdentifierName($class->name(), 'table', $this->config))]);
}

return $attributes;
Expand Down Expand Up @@ -150,7 +150,7 @@ public function generatePropertyAttributes(Property $property, string $className

foreach (self::RESERVED_KEYWORDS as $keyword) {
if (0 === strcasecmp($keyword, $property->name())) {
$args['name'] = sprintf('`%s`', $property->name());
$args['name'] = \sprintf('`%s`', $property->name());
break;
}
}
Expand Down Expand Up @@ -281,16 +281,16 @@ private function getRelationName(Property $property): ?string

if (null !== $reference->interfaceName()) {
if (isset($this->config['types'][$reference->name()]['namespaces']['interface'])) {
return sprintf('%s\\%s', $this->config['types'][$reference->name()]['namespaces']['interface'], $reference->interfaceName());
return \sprintf('%s\\%s', $this->config['types'][$reference->name()]['namespaces']['interface'], $reference->interfaceName());
}

return sprintf('%s\\%s', $this->config['namespaces']['interface'], $reference->interfaceName());
return \sprintf('%s\\%s', $this->config['namespaces']['interface'], $reference->interfaceName());
}

if (isset($this->config['types'][$reference->name()]['namespaces']['class'])) {
return sprintf('%s\\%s', $this->config['types'][$reference->name()]['namespaces']['class'], $reference->name());
return \sprintf('%s\\%s', $this->config['types'][$reference->name()]['namespaces']['class'], $reference->name());
}

return sprintf('%s\\%s', $this->config['namespaces']['entity'], $reference->name());
return \sprintf('%s\\%s', $this->config['namespaces']['entity'], $reference->name());
}
}
4 changes: 2 additions & 2 deletions src/ClassMutator/AnnotationsAppender.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ private function generateClassUses(Class_ $class): void
{
$interfaceNamespace = isset($this->classes[$class->name()]) ? $this->classes[$class->name()]->interfaceNamespace() : null;
if ($interfaceNamespace && $class->interfaceNamespace() !== $class->namespace) {
$class->addUse(new Use_(sprintf('%s\\%s', $class->interfaceNamespace(), $class->interfaceName())));
$class->addUse(new Use_(\sprintf('%s\\%s', $class->interfaceNamespace(), $class->interfaceName())));
}

foreach ($class->properties() as $property) {
if ($property->reference && $property->reference->interfaceName()) {
$class->addUse(new Use_(sprintf(
$class->addUse(new Use_(\sprintf(
'%s\\%s',
$property->reference->interfaceNamespace(),
$property->reference->interfaceName()
Expand Down
4 changes: 2 additions & 2 deletions src/ClassMutator/AttributeAppender.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ private function generateClassUses(Class_ $class): void
{
$interfaceNamespace = isset($this->classes[$class->name()]) ? $this->classes[$class->name()]->interfaceNamespace() : null;
if ($interfaceNamespace && $class->interfaceNamespace() !== $class->namespace) {
$class->addUse(new Use_(sprintf('%s\\%s', $class->interfaceNamespace(), $class->interfaceName())));
$class->addUse(new Use_(\sprintf('%s\\%s', $class->interfaceNamespace(), $class->interfaceName())));
}

foreach ($class->properties() as $property) {
if ($property->reference && $property->reference->interfaceName()) {
$class->addUse(new Use_(sprintf(
$class->addUse(new Use_(\sprintf(
'%s\\%s',
$property->reference->interfaceNamespace(),
$property->reference->interfaceName()
Expand Down
2 changes: 1 addition & 1 deletion src/ClassMutator/ClassInterfaceMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function __construct(string $desiredNamespace)
*/
public function __invoke(Class_ $class, array $context): void
{
$class->interface = new Interface_(sprintf('%sInterface', $class->name()), $this->desiredNamespace);
$class->interface = new Interface_(\sprintf('%sInterface', $class->name()), $this->desiredNamespace);
}
}
2 changes: 1 addition & 1 deletion src/ClassMutator/ClassParentMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __invoke(Class_ $class, array $context): void

if (null === $class->parent() && $subclassOf = $class->getSubClassOf()) {
if (\count($subclassOf) > 1) {
$this->logger ? $this->logger->info(sprintf('The type "%s" has several supertypes. Using the first one.', $class->rdfType())) : null;
$this->logger ? $this->logger->info(\sprintf('The type "%s" has several supertypes. Using the first one.', $class->rdfType())) : null;
}

if (\is_string($parentLocalName = $subclassOf[0]->localName())) {
Expand Down
6 changes: 3 additions & 3 deletions src/ClassMutator/ClassPropertiesAppender.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __invoke(Class_ $class, array $context): void
} else {
$remainingProperties = $typeConfig['properties'] ?? [];
if (!isset($this->propertiesMap[$class->rdfType()])) {
$this->logger ? $this->logger->warning(sprintf('Properties for "%s" not found in the map.', $class->rdfType())) : null;
$this->logger ? $this->logger->warning(\sprintf('Properties for "%s" not found in the map.', $class->rdfType())) : null;
}
// All properties
foreach ($this->propertiesMap[$class->rdfType()] ?? [] as $property) {
Expand All @@ -93,7 +93,7 @@ public function __invoke(Class_ $class, array $context): void
}
if ($property->hasProperty(self::SCHEMA_ORG_SUPERSEDED_BY)) {
$supersededBy = $property->get(self::SCHEMA_ORG_SUPERSEDED_BY);
$this->logger ? $this->logger->info(sprintf('The property "%s" is superseded by "%s". Using the superseding property.', $property->getUri(), $supersededBy->getUri())) : null;
$this->logger ? $this->logger->info(\sprintf('The property "%s" is superseded by "%s". Using the superseding property.', $property->getUri(), $supersededBy->getUri())) : null;
} else {
$this->generateField($this->config, $class, $class->resource(), $typeConfig, $cardinalities, $property);
}
Expand All @@ -117,7 +117,7 @@ public function __invoke(Class_ $class, array $context): void
*/
private function generateCustomField(string $propertyName, RdfResource $type, ?array $typeConfig, array $cardinalities, SchemaClass $class, array $config): void
{
$this->logger ? $this->logger->info(sprintf('The property "%s" (type "%s") is a custom property.', $propertyName, $type->getUri())) : null;
$this->logger ? $this->logger->info(\sprintf('The property "%s" (type "%s") is a custom property.', $propertyName, $type->getUri())) : null;
$customResource = new RdfResource('_:'.$propertyName, new RdfGraph());
$customResource->add('rdfs:range', $type);

Expand Down
16 changes: 8 additions & 8 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,45 +80,45 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($dir = realpath($outputDir)) {
if (!is_dir($dir)) {
if (!$defaultOutput) {
throw new \InvalidArgumentException(sprintf('The file "%s" is not a directory.', $dir));
throw new \InvalidArgumentException(\sprintf('The file "%s" is not a directory.', $dir));
}

$dir = $defaultOutput;
$configArgument = $outputDir;
}

if (!is_writable($dir)) {
throw new \InvalidArgumentException(sprintf('The "%s" directory is not writable.', $dir));
throw new \InvalidArgumentException(\sprintf('The "%s" directory is not writable.', $dir));
}

$outputDir = $dir;
} else {
(new Filesystem())->mkdir($outputDir);
$outputDir = realpath($outputDir);
if (!$outputDir) {
throw new \InvalidArgumentException(sprintf('The "%s" directory cannot be created.', $outputDir));
throw new \InvalidArgumentException(\sprintf('The "%s" directory cannot be created.', $outputDir));
}
}

if ($configArgument) {
if (!file_exists($configArgument)) {
throw new \InvalidArgumentException(sprintf('The file "%s" doesn\'t exist.', $configArgument));
throw new \InvalidArgumentException(\sprintf('The file "%s" doesn\'t exist.', $configArgument));
}

if (!is_file($configArgument)) {
throw new \InvalidArgumentException(sprintf('"%s" isn\'t a file.', $configArgument));
throw new \InvalidArgumentException(\sprintf('"%s" isn\'t a file.', $configArgument));
}

if (!is_readable($configArgument)) {
throw new \InvalidArgumentException(sprintf('The file "%s" isn\'t readable.', $configArgument));
throw new \InvalidArgumentException(\sprintf('The file "%s" isn\'t readable.', $configArgument));
}

if (false === ($configContent = file_get_contents($configArgument))) {
throw new \RuntimeException(sprintf('Cannot read "%s" content.', $configArgument));
throw new \RuntimeException(\sprintf('Cannot read "%s" content.', $configArgument));
}
} elseif (is_readable(self::DEFAULT_CONFIG_FILE)) {
if (false === ($configContent = file_get_contents(self::DEFAULT_CONFIG_FILE))) {
throw new \RuntimeException(sprintf('Cannot read "%s" content.', self::DEFAULT_CONFIG_FILE));
throw new \RuntimeException(\sprintf('Cannot read "%s" content.', self::DEFAULT_CONFIG_FILE));
}
} else {
if (!$io->askQuestion(new ConfirmationQuestion('Your project has no config file. The entire vocabulary will be imported.'.\PHP_EOL.'Continue?', false))) {
Expand Down
Loading
Loading