Skip to content

Commit

Permalink
apply cs fix to all dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Apr 23, 2019
1 parent 5f10429 commit d88030d
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 65 deletions.
23 changes: 22 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
<?php
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer

$dirs = [
__DIR__.'/Adapter',
__DIR__.'/Command',
__DIR__.'/DataCollector',
__DIR__.'/DependencyInjection',
__DIR__.'/Entity',
__DIR__.'/Event',
__DIR__.'/EventListener',
__DIR__.'/Exception',
__DIR__.'/Form',
__DIR__.'/Handler',
__DIR__.'/Injector',
__DIR__.'/Mapping',
__DIR__.'/Metadata',
__DIR__.'/Naming',
__DIR__.'/Storage',
__DIR__.'/Tests',
__DIR__.'/Twig',
__DIR__.'/Util',
];

$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/Command', __DIR__.'/DependencyInjection', __DIR__.'/Form', __DIR__.'/Tests', __DIR__.'/Twig', __DIR__.'/Util'])
->in($dirs)
;

return PhpCsFixer\Config::create()
Expand Down
2 changes: 1 addition & 1 deletion Adapter/ODM/MongoDB/MongoDBAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function recomputeChangeSet($event): void

$dm = $event->getDocumentManager();
$uow = $dm->getUnitOfWork();
$metadata = $dm->getClassMetadata(get_class($object));
$metadata = $dm->getClassMetadata(\get_class($object));
$uow->recomputeSingleDocumentChangeSet($metadata, $object);
}
}
2 changes: 1 addition & 1 deletion Adapter/ORM/DoctrineORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function recomputeChangeSet($event): void

$em = $event->getEntityManager();
$uow = $em->getUnitOfWork();
$metadata = $em->getClassMetadata(get_class($object));
$metadata = $em->getClassMetadata(\get_class($object));
$uow->recomputeSingleEntityChangeSet($metadata, $object);
}
}
2 changes: 1 addition & 1 deletion DataCollector/MappingCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Vich\UploaderBundle\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Vich\UploaderBundle\Metadata\MetadataReader;

final class MappingCollector extends DataCollector
Expand Down
2 changes: 1 addition & 1 deletion EventListener/Doctrine/BaseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getUploadableFields($object): array
{
$fields = $this->metadata->getUploadableFields(ClassUtils::getClass($object), $this->mapping);

return array_map(function ($data) {
return \array_map(function ($data) {
return $data['propertyName'];
}, $fields);
}
Expand Down
2 changes: 1 addition & 1 deletion EventListener/Propel/BaseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getUploadableFields($object): array
{
$fields = $this->metadata->getUploadableFields(ClassUtils::getClass($object), $this->mapping);

return array_map(function ($data) {
return \array_map(function ($data) {
return $data['propertyName'];
}, $fields);
}
Expand Down
6 changes: 3 additions & 3 deletions Exception/MappingNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ class MappingNotFoundException extends \RuntimeException
public static function createNotFoundForClassAndField($mapping, $class, $field): self
{
return new self(
sprintf('Mapping "%s" does not exist. The configuration for the class "%s" is probably incorrect as the mapping to use for the field "%s" could not be found.', $mapping, $class, $field)
\sprintf('Mapping "%s" does not exist. The configuration for the class "%s" is probably incorrect as the mapping to use for the field "%s" could not be found.', $mapping, $class, $field)
);
}

public static function createNotFoundForClass(string $mapping, string $class): self
{
if ('' === $mapping) {
return new self(
sprintf('Mapping not found. The configuration for the class "%s" is probably incorrect.', $class)
\sprintf('Mapping not found. The configuration for the class "%s" is probably incorrect.', $class)
);
}

return new self(
sprintf('Mapping "%s" does not exist. The configuration for the class "%s" is probably incorrect.', $mapping, $class)
\sprintf('Mapping "%s" does not exist. The configuration for the class "%s" is probably incorrect.', $mapping, $class)
);
}
}
2 changes: 1 addition & 1 deletion Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getMapping($obj, string $fieldName, ?string $className = null
$mapping = $this->factory->fromField($obj, $fieldName, $className);

if (null === $mapping) {
throw new MappingNotFoundException(sprintf('Mapping not found for field "%s"', $fieldName));
throw new MappingNotFoundException(\sprintf('Mapping not found for field "%s"', $fieldName));
}

return $mapping;
Expand Down
4 changes: 2 additions & 2 deletions Handler/DownloadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function downloadObject($object, string $field, ?string $className = null
$stream = $this->storage->resolveStream($object, $field, $className);

if (null === $stream) {
throw new NoFileFoundException(sprintf('No file found in field "%s".', $field));
throw new NoFileFoundException(\sprintf('No file found in field "%s".', $field));
}

if (true === $fileName) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public function downloadObject($object, string $field, ?string $className = null
private function createDownloadResponse($stream, string $filename, ?string $mimeType = 'application/octet-stream', bool $forceDownload = true): StreamedResponse
{
$response = new StreamedResponse(function () use ($stream): void {
stream_copy_to_stream($stream, fopen('php://output', 'wb'));
\stream_copy_to_stream($stream, \fopen('php://output', 'w'));
});

$disposition = $response->headers->makeDisposition(
Expand Down
4 changes: 2 additions & 2 deletions Mapping/Annotation/UploadableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function __construct(array $options)
}

foreach ($options as $property => $value) {
if (!property_exists($this, $property)) {
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $property, get_class($this)));
if (!\property_exists($this, $property)) {
throw new \RuntimeException(\sprintf('Unknown key "%s" for annotation "@%s".', $property, \get_class($this)));
}

$this->$property = $value;
Expand Down
16 changes: 8 additions & 8 deletions Mapping/PropertyMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PropertyMapping
*/
public function __construct(string $filePropertyPath, string $fileNamePropertyPath, array $propertyPaths = [])
{
$this->propertyPaths = array_merge(
$this->propertyPaths = \array_merge(
$this->propertyPaths,
['file' => $filePropertyPath, 'name' => $fileNamePropertyPath],
$propertyPaths
Expand Down Expand Up @@ -151,8 +151,8 @@ public function erase($obj): void
*/
public function readProperty($obj, $property)
{
if (!array_key_exists($property, $this->propertyPaths)) {
throw new \InvalidArgumentException(sprintf('Unknown property %s', $property));
if (!\array_key_exists($property, $this->propertyPaths)) {
throw new \InvalidArgumentException(\sprintf('Unknown property %s', $property));
}

if (!$this->propertyPaths[$property]) {
Expand All @@ -179,8 +179,8 @@ public function readProperty($obj, $property)
*/
public function writeProperty($obj, string $property, $value): void
{
if (!array_key_exists($property, $this->propertyPaths)) {
throw new \InvalidArgumentException(sprintf('Unknown property %s', $property));
if (!\array_key_exists($property, $this->propertyPaths)) {
throw new \InvalidArgumentException(\sprintf('Unknown property %s', $property));
}

if (!$this->propertyPaths[$property]) {
Expand Down Expand Up @@ -334,7 +334,7 @@ public function getUploadDir($obj): ?string
$dir = $this->getDirectoryNamer()->directoryName($obj, $this);

// strip the trailing directory separator if needed
$dir = $dir ? rtrim($dir, '/\\') : $dir;
$dir = $dir ? \rtrim($dir, '/\\') : $dir;

return $dir;
}
Expand Down Expand Up @@ -372,11 +372,11 @@ public function getUriPrefix(): string
*/
protected function fixPropertyPath($object, string $propertyPath): string
{
if (!is_array($object)) {
if (!\is_array($object)) {
return $propertyPath;
}

return '[' === $propertyPath[0] ? $propertyPath : sprintf('[%s]', $propertyPath);
return '[' === $propertyPath[0] ? $propertyPath : \sprintf('[%s]', $propertyPath);
}

protected function getAccessor(): PropertyAccessor
Expand Down
10 changes: 5 additions & 5 deletions Mapping/PropertyMappingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function fromField($obj, string $field, ?string $className = null): ?Prop
protected function checkUploadable(string $class): void
{
if (!$this->metadata->isUploadable($class)) {
throw new NotUploadableException(sprintf('The class "%s" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add `@Vich\Uploadable` on top of your entity. If you don\'t use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.', $class));
throw new NotUploadableException(\sprintf('The class "%s" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add `@Vich\Uploadable` on top of your entity. If you don\'t use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.', $class));
}
}

Expand All @@ -140,7 +140,7 @@ protected function checkUploadable(string $class): void
*/
protected function createMapping($obj, string $fieldName, array $mappingData): PropertyMapping
{
if (!array_key_exists($mappingData['mapping'], $this->mappings)) {
if (!\array_key_exists($mappingData['mapping'], $this->mappings)) {
throw MappingNotFoundException::createNotFoundForClassAndField($mappingData['mapping'], $this->getClassName($obj), $fieldName);
}

Expand All @@ -158,7 +158,7 @@ protected function createMapping($obj, string $fieldName, array $mappingData): P

if (!empty($namerConfig['options'])) {
if (!$namer instanceof ConfigurableInterface) {
throw new \LogicException(sprintf('Namer %s can not receive options as it does not implement ConfigurableInterface.', $namerConfig['service']));
throw new \LogicException(\sprintf('Namer %s can not receive options as it does not implement ConfigurableInterface.', $namerConfig['service']));
}
$namer->configure($namerConfig['options']);
}
Expand All @@ -172,7 +172,7 @@ protected function createMapping($obj, string $fieldName, array $mappingData): P

if (!empty($namerConfig['options'])) {
if (!$namer instanceof ConfigurableInterface) {
throw new \LogicException(sprintf('Namer %s can not receive options as it does not implement ConfigurableInterface.', $namerConfig['service']));
throw new \LogicException(\sprintf('Namer %s can not receive options as it does not implement ConfigurableInterface.', $namerConfig['service']));
}
$namer->configure($namerConfig['options']);
}
Expand All @@ -199,7 +199,7 @@ protected function getClassName($object, ?string $className = null): string
return $className;
}

if (is_object($object)) {
if (\is_object($object)) {
return ClassUtils::getClass($object);
}

Expand Down
4 changes: 2 additions & 2 deletions Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ClassMetadata extends BaseClassMetadata

public function serialize(): string
{
return serialize([
return \serialize([
$this->fields,
parent::serialize(),
]);
Expand All @@ -21,7 +21,7 @@ public function unserialize($str): void
[
$this->fields,
$parentStr
] = unserialize($str);
] = \unserialize($str);

parent::unserialize($parentStr);
}
Expand Down
4 changes: 2 additions & 2 deletions Metadata/MetadataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public function getUploadableFields(string $class, ?string $mapping = null): arr
$uploadableFields = [];

foreach ($metadata->classMetadata as $classMetadata) {
$uploadableFields = array_merge($uploadableFields, $classMetadata->fields);
$uploadableFields = \array_merge($uploadableFields, $classMetadata->fields);
}

if (null !== $mapping) {
$uploadableFields = array_filter($uploadableFields, function (array $fieldMetadata) use ($mapping) {
$uploadableFields = \array_filter($uploadableFields, function (array $fieldMetadata) use ($mapping) {
return $fieldMetadata['mapping'] === $mapping;
});
}
Expand Down
2 changes: 1 addition & 1 deletion Naming/Base64Namer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public function name($object, PropertyMapping $mapping): string

protected function getRandomChar(): string
{
return self::ALPHABET[random_int(0, 63)];
return self::ALPHABET[\random_int(0, 63)];
}
}
4 changes: 2 additions & 2 deletions Naming/CurrentDateTimeDirectoryNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(DateTimeHelper $dateTimeHelper, ?PropertyAccessorInt
*/
public function configure(array $options): void
{
$options = array_merge(['date_time_format' => $this->dateTimeFormat], $options);
$options = \array_merge(['date_time_format' => $this->dateTimeFormat], $options);

$this->dateTimeFormat = $options['date_time_format'];

Expand All @@ -70,6 +70,6 @@ public function directoryName($object, PropertyMapping $mapping): string
$dateTime = $this->dateTimeHelper->getTimestamp();
}

return date($this->dateTimeFormat, $dateTime);
return \date($this->dateTimeFormat, $dateTime);
}
}
2 changes: 1 addition & 1 deletion Naming/CurrentDateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class CurrentDateTimeHelper implements DateTimeHelper
*/
public function getTimestamp(): int
{
return time();
return \time();
}
}
10 changes: 5 additions & 5 deletions Naming/HashNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HashNamer implements NamerInterface, ConfigurableInterface
*/
public function configure(array $options): void
{
$options = array_merge(['algorithm' => $this->algorithm, 'length' => $this->length], $options);
$options = \array_merge(['algorithm' => $this->algorithm, 'length' => $this->length], $options);

$this->algorithm = $options['algorithm'];
$this->length = $options['length'];
Expand All @@ -34,20 +34,20 @@ public function name($object, PropertyMapping $mapping): string
{
$file = $mapping->getFile($object);

$name = hash($this->algorithm, $this->getRandomString());
$name = \hash($this->algorithm, $this->getRandomString());
if (null !== $this->length) {
$name = substr($name, 0, $this->length);
$name = \substr($name, 0, $this->length);
}

if ($extension = $this->getExtension($file)) {
$name = sprintf('%s.%s', $name, $extension);
$name = \sprintf('%s.%s', $name, $extension);
}

return $name;
}

protected function getRandomString(): string
{
return microtime(true).random_int(0, 9999999);
return \microtime(true).\random_int(0, 9999999);
}
}
2 changes: 1 addition & 1 deletion Naming/OrignameNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function name($object, PropertyMapping $mapping): string
$name = Transliterator::transliterate($name);
}

return uniqid().'_'.$name;
return \uniqid().'_'.$name;
}
}
2 changes: 1 addition & 1 deletion Naming/Polyfill/FileExtensionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private function getExtension(UploadedFile $file): ?string
{
$originalName = $file->getClientOriginalName();

if ($extension = pathinfo($originalName, PATHINFO_EXTENSION)) {
if ($extension = \pathinfo($originalName, PATHINFO_EXTENSION)) {
return $extension;
}

Expand Down
4 changes: 2 additions & 2 deletions Naming/PropertyDirectoryNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function directoryName($object, PropertyMapping $mapping): string
try {
$name = $this->propertyAccessor->getValue($object, $this->propertyPath);
} catch (NoSuchPropertyException $e) {
throw new NameGenerationException(sprintf('Directory name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
throw new NameGenerationException(\sprintf('Directory name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
}

if (empty($name)) {
throw new NameGenerationException(sprintf('Directory name could not be generated: property %s is empty.', $this->propertyPath));
throw new NameGenerationException(\sprintf('Directory name could not be generated: property %s is empty.', $this->propertyPath));
}

if ($this->transliterate) {
Expand Down
6 changes: 3 additions & 3 deletions Naming/PropertyNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public function name($object, PropertyMapping $mapping): string
try {
$name = $this->getPropertyValue($object, $this->propertyPath);
} catch (NoSuchPropertyException $e) {
throw new NameGenerationException(sprintf('File name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
throw new NameGenerationException(\sprintf('File name could not be generated: property %s does not exist.', $this->propertyPath), $e->getCode(), $e);
}

if (empty($name)) {
throw new NameGenerationException(sprintf('File name could not be generated: property %s is empty.', $this->propertyPath));
throw new NameGenerationException(\sprintf('File name could not be generated: property %s is empty.', $this->propertyPath));
}

if ($this->transliterate) {
Expand All @@ -68,7 +68,7 @@ public function name($object, PropertyMapping $mapping): string

// append the file extension if there is one
if ($extension = $this->getExtension($file)) {
$name = sprintf('%s.%s', $name, $extension);
$name = \sprintf('%s.%s', $name, $extension);
}

return $name;
Expand Down
Loading

0 comments on commit d88030d

Please sign in to comment.