From 5e3d634e00676250e7096c10bdcfa216978a1944 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Mon, 9 Jan 2017 09:03:02 +0100 Subject: [PATCH] big coding standard fix --- Adapter/AdapterInterface.php | 7 +- Adapter/ODM/MongoDB/MongoDBAdapter.php | 4 +- Adapter/ORM/DoctrineORMAdapter.php | 4 +- Adapter/PHPCR/PHPCRAdapter.php | 4 +- Adapter/Propel/PropelORMAdapter.php | 4 +- Command/MappingDebugClassCommand.php | 3 +- Command/MappingDebugCommand.php | 5 +- Command/MappingListClassesCommand.php | 2 +- .../Compiler/RegisterPropelModelsPass.php | 9 +- DependencyInjection/Configuration.php | 30 ++- DependencyInjection/VichUploaderExtension.php | 40 +-- Event/Event.php | 1 - Event/Events.php | 12 +- EventListener/Doctrine/BaseListener.php | 25 +- EventListener/Doctrine/CleanListener.php | 10 +- EventListener/Doctrine/InjectListener.php | 10 +- EventListener/Doctrine/RemoveListener.php | 20 +- EventListener/Doctrine/UploadListener.php | 12 +- EventListener/Propel/BaseListener.php | 23 +- EventListener/Propel/CleanListener.php | 10 +- EventListener/Propel/InjectListener.php | 10 +- EventListener/Propel/RemoveListener.php | 10 +- EventListener/Propel/UploadListener.php | 10 +- Exception/MappingNotFoundException.php | 2 +- Form/DataTransformer/FileTransformer.php | 4 +- Form/Type/VichFileType.php | 6 +- Handler/AbstractHandler.php | 6 +- Handler/DownloadHandler.php | 3 +- Handler/UploadHandler.php | 16 +- Injector/FileInjector.php | 5 +- Injector/FileInjectorInterface.php | 4 +- Mapping/Annotation/UploadableField.php | 11 +- Mapping/PropertyMapping.php | 66 ++--- Mapping/PropertyMappingFactory.php | 51 ++-- Metadata/ClassMetadata.php | 8 +- Metadata/Driver/AbstractFileDriver.php | 4 +- Metadata/Driver/AnnotationDriver.php | 17 +- Metadata/Driver/ChainDriver.php | 6 +- Metadata/Driver/FileLocator.php | 2 +- Metadata/Driver/XmlDriver.php | 14 +- Metadata/Driver/YamlDriver.php | 17 +- Metadata/MetadataReader.php | 20 +- Naming/ConfigurableInterface.php | 2 +- Naming/DirectoryNamerInterface.php | 6 +- Naming/HashNamer.php | 6 +- Naming/NamerInterface.php | 6 +- Naming/OrignameNamer.php | 9 +- Naming/PropertyNamer.php | 9 +- Naming/SubdirDirectoryNamer.php | 8 +- Naming/UniqidNamer.php | 4 +- Storage/AbstractStorage.php | 34 +-- Storage/FileSystemStorage.php | 8 +- Storage/FlysystemStorage.php | 18 +- Storage/GaufretteStorage.php | 18 +- Storage/StorageInterface.php | 34 +-- Templating/Helper/UploaderHelper.php | 12 +- Tests/Adapter/Propel/PropelORMAdapterTest.php | 2 +- .../VichUploaderExtensionTest.php | 83 +++---- Tests/DummyEntity.php | 4 +- .../Doctrine/CleanListenerTest.php | 10 +- .../Doctrine/InjectListenerTest.php | 10 +- .../Doctrine/ListenerTestCase.php | 16 +- .../Doctrine/RemoveListenerTest.php | 10 +- .../Doctrine/UploadListenerTest.php | 16 +- .../Propel/CleanListenerTest.php | 2 +- .../Propel/InjectListenerTest.php | 2 +- .../EventListener/Propel/ListenerTestCase.php | 24 +- .../Propel/RemoveListenerTest.php | 2 +- .../Propel/UploadListenerTest.php | 2 +- Tests/Fixtures/App/app/AppKernel.php | 4 +- .../Controller/DefaultController.php | 2 +- .../App/src/TestBundle/Entity/Image.php | 4 +- Tests/Functional/UploadTest.php | 56 ++--- Tests/Functional/WebTestCase.php | 7 +- Tests/Handler/UploadHandlerTest.php | 22 +- Tests/Injector/FileInjectorTest.php | 3 +- .../Annotation/UploadableFieldTest.php | 6 +- Tests/Mapping/PropertyMappingFactoryTest.php | 234 +++++++++--------- Tests/Mapping/PropertyMappingTest.php | 40 +-- Tests/Metadata/ClassMetadataTest.php | 2 +- .../Metadata/Driver/AnnotationDriverTest.php | 64 ++--- Tests/Metadata/Driver/FileLocatorTest.php | 47 ++-- Tests/Metadata/Driver/YamlDriverTest.php | 94 +++---- Tests/Metadata/MetadataReaderTest.php | 50 ++-- Tests/Naming/HashNamerTest.php | 14 +- Tests/Naming/OrignameNamerTest.php | 12 +- Tests/Naming/PropertyNamerTest.php | 26 +- Tests/Naming/SubdirDirectoryNamerTest.php | 17 +- Tests/Naming/UniqidNamerTest.php | 12 +- Tests/Storage/FileSystemStorageTest.php | 54 ++-- Tests/Storage/FlysystemStorageTest.php | 21 +- Tests/Storage/GaufretteStorageTest.php | 33 ++- Tests/Storage/StorageTestCase.php | 35 ++- Tests/Templating/Helper/UploadHelperTest.php | 2 +- Tests/TestCase.php | 4 +- .../Twig/Extension/UploaderExtensionTest.php | 2 +- Tests/bootstrap.php | 2 +- Twig/Extension/UploaderExtension.php | 16 +- Util/ClassUtils.php | 4 +- VichUploaderBundle.php | 1 - 100 files changed, 884 insertions(+), 890 deletions(-) diff --git a/Adapter/AdapterInterface.php b/Adapter/AdapterInterface.php index 45b7ea01..9b54695a 100644 --- a/Adapter/AdapterInterface.php +++ b/Adapter/AdapterInterface.php @@ -12,15 +12,16 @@ interface AdapterInterface /** * Gets the mapped object from an event. * - * @param object $event The event. - * @return object The mapped object. + * @param object $event The event + * + * @return object The mapped object */ public function getObjectFromArgs($event); /** * Recomputes the change set for the object. * - * @param object $event The event. + * @param object $event The event */ public function recomputeChangeSet($event); } diff --git a/Adapter/ODM/MongoDB/MongoDBAdapter.php b/Adapter/ODM/MongoDB/MongoDBAdapter.php index 730c8123..c02dc43f 100644 --- a/Adapter/ODM/MongoDB/MongoDBAdapter.php +++ b/Adapter/ODM/MongoDB/MongoDBAdapter.php @@ -12,7 +12,7 @@ class MongoDBAdapter implements AdapterInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getObjectFromArgs($event) { @@ -20,7 +20,7 @@ public function getObjectFromArgs($event) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function recomputeChangeSet($event) { diff --git a/Adapter/ORM/DoctrineORMAdapter.php b/Adapter/ORM/DoctrineORMAdapter.php index 64446cf8..49e1d0e7 100644 --- a/Adapter/ORM/DoctrineORMAdapter.php +++ b/Adapter/ORM/DoctrineORMAdapter.php @@ -12,7 +12,7 @@ class DoctrineORMAdapter implements AdapterInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getObjectFromArgs($event) { @@ -20,7 +20,7 @@ public function getObjectFromArgs($event) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function recomputeChangeSet($event) { diff --git a/Adapter/PHPCR/PHPCRAdapter.php b/Adapter/PHPCR/PHPCRAdapter.php index 7f437336..ba22a1fc 100644 --- a/Adapter/PHPCR/PHPCRAdapter.php +++ b/Adapter/PHPCR/PHPCRAdapter.php @@ -12,7 +12,7 @@ class PHPCRAdapter implements AdapterInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getObjectFromArgs($event) { @@ -20,7 +20,7 @@ public function getObjectFromArgs($event) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function recomputeChangeSet($event) { diff --git a/Adapter/Propel/PropelORMAdapter.php b/Adapter/Propel/PropelORMAdapter.php index c21c6e7c..c92a4c82 100644 --- a/Adapter/Propel/PropelORMAdapter.php +++ b/Adapter/Propel/PropelORMAdapter.php @@ -12,7 +12,7 @@ class PropelORMAdapter implements AdapterInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getObjectFromArgs($event) { @@ -20,7 +20,7 @@ public function getObjectFromArgs($event) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function recomputeChangeSet($event) { diff --git a/Command/MappingDebugClassCommand.php b/Command/MappingDebugClassCommand.php index fe0dc156..82fd6146 100644 --- a/Command/MappingDebugClassCommand.php +++ b/Command/MappingDebugClassCommand.php @@ -21,10 +21,11 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $metadataReader = $this->getContainer()->get('vich_uploader.metadata_reader'); - $fqcn = $input->getArgument('fqcn'); + $fqcn = $input->getArgument('fqcn'); if (!$metadataReader->isUploadable($fqcn)) { $output->writeln(sprintf('"%s" is not uploadable.', $fqcn)); + return 1; } diff --git a/Command/MappingDebugCommand.php b/Command/MappingDebugCommand.php index 256e9c01..4153563a 100644 --- a/Command/MappingDebugCommand.php +++ b/Command/MappingDebugCommand.php @@ -6,7 +6,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; - use Vich\UploaderBundle\Exception\MappingNotFoundException; class MappingDebugCommand extends ContainerAwareCommand @@ -23,7 +22,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $mappings = $this->getContainer()->getParameter('vich_uploader.mappings'); - $mapping = $input->getArgument('mapping'); + $mapping = $input->getArgument('mapping'); if (!isset($mappings[$mapping])) { throw new MappingNotFoundException(sprintf('Mapping "%s" does not exist.', $mapping)); @@ -31,7 +30,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf('Debug information for mapping %s', $mapping)); - foreach($mappings[$mapping] as $key => $value) { + foreach ($mappings[$mapping] as $key => $value) { $output->writeln(sprintf('%s: %s', $key, var_export($value, true))); } } diff --git a/Command/MappingListClassesCommand.php b/Command/MappingListClassesCommand.php index 9632ddc6..a9b81226 100644 --- a/Command/MappingListClassesCommand.php +++ b/Command/MappingListClassesCommand.php @@ -20,7 +20,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Looking for uploadable classes.'); - $metadataReader = $this->getContainer()->get('vich_uploader.metadata_reader'); + $metadataReader = $this->getContainer()->get('vich_uploader.metadata_reader'); $uploadableClasses = $metadataReader->getUploadableClasses(); foreach ($uploadableClasses as $class) { diff --git a/DependencyInjection/Compiler/RegisterPropelModelsPass.php b/DependencyInjection/Compiler/RegisterPropelModelsPass.php index 99912600..11089adf 100644 --- a/DependencyInjection/Compiler/RegisterPropelModelsPass.php +++ b/DependencyInjection/Compiler/RegisterPropelModelsPass.php @@ -4,11 +4,10 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; - use Vich\UploaderBundle\Exception\MappingNotFoundException; /** - * Register the uploadable models in BazingaPropelEventDispatcherBundle + * Register the uploadable models in BazingaPropelEventDispatcherBundle. * * @author Kévin Gomez */ @@ -37,9 +36,9 @@ public function process(ContainerBuilder $container) return; } - $serviceTypes = array( + $serviceTypes = [ 'inject', 'clean', 'remove', 'upload', - ); + ]; $metadata = $container->get('vich_uploader.metadata_reader'); @@ -63,7 +62,7 @@ public function process(ContainerBuilder $container) $definition = $container->getDefinition(sprintf('vich_uploader.listener.%s.%s', $type, $field['mapping'])); $definition->setClass($container->getDefinition($definition->getParent())->getClass()); $definition->setPublic(true); - $definition->addTag('propel.event_subscriber', array('class' => $class)); + $definition->addTag('propel.event_subscriber', ['class' => $class]); } } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 487c58e0..9bd4e875 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -13,8 +13,8 @@ */ class Configuration implements ConfigurationInterface { - protected $supportedDbDrivers = array('orm', 'mongodb', 'propel', 'phpcr'); - protected $supportedStorages = array('gaufrette', 'flysystem', 'file_system'); + protected $supportedDbDrivers = ['orm', 'mongodb', 'propel', 'phpcr']; + protected $supportedStorages = ['gaufrette', 'flysystem', 'file_system']; /** * Gets the configuration tree builder for the extension. @@ -44,24 +44,28 @@ protected function addGeneralSection(ArrayNodeDefinition $node) ->isRequired() ->beforeNormalization() ->ifString() - ->then(function ($v) { return strtolower($v); }) + ->then(function ($v) { + return strtolower($v); + }) ->end() ->validate() ->ifNotInArray($this->supportedDbDrivers) - ->thenInvalid('The db driver %s is not supported. Please choose one of ' . implode(', ', $this->supportedDbDrivers)) + ->thenInvalid('The db driver %s is not supported. Please choose one of '.implode(', ', $this->supportedDbDrivers)) ->end() ->end() ->scalarNode('storage') ->defaultValue('file_system') ->beforeNormalization() ->ifString() - ->then(function ($v) { return strtolower($v); }) + ->then(function ($v) { + return strtolower($v); + }) ->end() ->validate() ->ifTrue(function ($storage) { return strpos($storage, '@') !== 0 && !in_array($storage, $this->supportedStorages, true); }) - ->thenInvalid('The storage %s is not supported. Please choose one of ' . implode(', ', $this->supportedStorages) . ' or provide a service name prefixed with "@".') + ->thenInvalid('The storage %s is not supported. Please choose one of '.implode(', ', $this->supportedStorages).' or provide a service name prefixed with "@".') ->end() ->end() ->scalarNode('twig')->defaultTrue()->end() @@ -112,7 +116,9 @@ protected function addMappingsSection(ArrayNodeDefinition $node) ->addDefaultsIfNotSet() ->beforeNormalization() ->ifString() - ->then(function ($v) { return array('service' => $v, 'options' => array()); }) + ->then(function ($v) { + return ['service' => $v, 'options' => []]; + }) ->end() ->children() ->scalarNode('service')->defaultNull()->end() @@ -123,7 +129,9 @@ protected function addMappingsSection(ArrayNodeDefinition $node) ->addDefaultsIfNotSet() ->beforeNormalization() ->ifString() - ->then(function ($v) { return array('service' => $v, 'options' => array()); }) + ->then(function ($v) { + return ['service' => $v, 'options' => []]; + }) ->end() ->children() ->scalarNode('service')->defaultNull()->end() @@ -137,11 +145,13 @@ protected function addMappingsSection(ArrayNodeDefinition $node) ->defaultNull() ->beforeNormalization() ->ifString() - ->then(function ($v) { return strtolower($v); }) + ->then(function ($v) { + return strtolower($v); + }) ->end() ->validate() ->ifNotInArray($this->supportedDbDrivers) - ->thenInvalid('The db driver %s is not supported. Please choose one of ' . implode(', ', $this->supportedDbDrivers)) + ->thenInvalid('The db driver %s is not supported. Please choose one of '.implode(', ', $this->supportedDbDrivers)) ->end() ->end() ->end() diff --git a/DependencyInjection/VichUploaderExtension.php b/DependencyInjection/VichUploaderExtension.php index e3e04c94..56dd7064 100644 --- a/DependencyInjection/VichUploaderExtension.php +++ b/DependencyInjection/VichUploaderExtension.php @@ -18,13 +18,13 @@ class VichUploaderExtension extends Extension { /** - * @var array $tagMap + * @var array */ - protected $tagMap = array( - 'orm' => 'doctrine.event_subscriber', - 'mongodb' => 'doctrine_mongodb.odm.event_subscriber', - 'phpcr' => 'doctrine_phpcr.event_subscriber' - ); + protected $tagMap = [ + 'orm' => 'doctrine.event_subscriber', + 'mongodb' => 'doctrine_mongodb.odm.event_subscriber', + 'phpcr' => 'doctrine_phpcr.event_subscriber', + ]; /** * Loads the extension. @@ -47,7 +47,7 @@ public function load(array $configs, ContainerBuilder $container) if (strpos($config['storage'], '@') === 0) { $container->setAlias('vich_uploader.storage', substr($config['storage'], 1)); } else { - $container->setAlias('vich_uploader.storage', 'vich_uploader.storage.' . $config['storage']); + $container->setAlias('vich_uploader.storage', 'vich_uploader.storage.'.$config['storage']); } $this->loadServicesFiles($container, $config); @@ -61,17 +61,17 @@ protected function loadServicesFiles(ContainerBuilder $container, array $config) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $toLoad = array( + $toLoad = [ 'adapter.xml', 'listener.xml', 'storage.xml', 'injector.xml', 'templating.xml', 'mapping.xml', 'factory.xml', 'namer.xml', - 'form.xml', 'handler.xml' - ); + 'form.xml', 'handler.xml', + ]; foreach ($toLoad as $file) { $loader->load($file); } - if (in_array($config['storage'], array('gaufrette', 'flysystem'))) { - $loader->load($config['storage'] . '.xml'); + if (in_array($config['storage'], ['gaufrette', 'flysystem'])) { + $loader->load($config['storage'].'.xml'); } if ($config['twig']) { @@ -84,7 +84,7 @@ protected function registerMetadataDirectories(ContainerBuilder $container, arra $bundles = $container->getParameter('kernel.bundles'); // directories - $directories = array(); + $directories = []; if ($config['metadata']['auto_detection']) { foreach ($bundles as $class) { $ref = new \ReflectionClass($class); @@ -152,11 +152,11 @@ protected function fixDbDriverConfig(array $config) protected function registerListeners(ContainerBuilder $container, array $config) { - $servicesMap = array( - 'inject_on_load' => array('name' => 'inject', 'priority' => 0), - 'delete_on_update' => array('name' => 'clean', 'priority' => 50), - 'delete_on_remove' => array('name' => 'remove', 'priority' => 0) - ); + $servicesMap = [ + 'inject_on_load' => ['name' => 'inject', 'priority' => 0], + 'delete_on_update' => ['name' => 'clean', 'priority' => 50], + 'delete_on_remove' => ['name' => 'remove', 'priority' => 0], + ]; foreach ($config['mappings'] as $name => $mapping) { $driver = $mapping['db_driver']; @@ -188,7 +188,7 @@ protected function createNamerServices(ContainerBuilder $container, array $confi protected function createNamerService(ContainerBuilder $container, $mappingName, array $mapping) { - $serviceId = sprintf('%s.%s', $mapping['namer']['service'], $mappingName); + $serviceId = sprintf('%s.%s', $mapping['namer']['service'], $mappingName); $container->setDefinition( $serviceId, new DefinitionDecorator($mapping['namer']['service']) ); @@ -207,7 +207,7 @@ protected function createListener(ContainerBuilder $container, $name, $type, $dr // propel does not require tags to work if (isset($this->tagMap[$driver])) { - $definition->addTag($this->tagMap[$driver], array('priority' => $priority)); + $definition->addTag($this->tagMap[$driver], ['priority' => $priority]); } } } diff --git a/Event/Event.php b/Event/Event.php index 7b0bff00..c983dfa1 100644 --- a/Event/Event.php +++ b/Event/Event.php @@ -3,7 +3,6 @@ namespace Vich\UploaderBundle\Event; use Symfony\Component\EventDispatcher\Event as BaseEvent; - use Vich\UploaderBundle\Mapping\PropertyMapping; /** diff --git a/Event/Events.php b/Event/Events.php index 0bfdfeda..1f55913f 100644 --- a/Event/Events.php +++ b/Event/Events.php @@ -16,7 +16,7 @@ final class Events * * @Event("Vich\UploaderBundle\Event\Event") */ - const PRE_UPLOAD = 'vich_uploader.pre_upload'; + const PRE_UPLOAD = 'vich_uploader.pre_upload'; /** * Triggered right after a file upload is handled. @@ -25,33 +25,33 @@ final class Events * * @Event("Vich\UploaderBundle\Event\Event") */ - const POST_UPLOAD = 'vich_uploader.post_upload'; + const POST_UPLOAD = 'vich_uploader.post_upload'; /** * Triggered before a file is injected into an entity. * * @Event("Vich\UploaderBundle\Event\Event") */ - const PRE_INJECT = 'vich_uploader.pre_inject'; + const PRE_INJECT = 'vich_uploader.pre_inject'; /** * Triggered after a file is injected into an entity. * * @Event("Vich\UploaderBundle\Event\Event") */ - const POST_INJECT = 'vich_uploader.post_inject'; + const POST_INJECT = 'vich_uploader.post_inject'; /** * Triggered before a file is removed. * * @Event("Vich\UploaderBundle\Event\Event") */ - const PRE_REMOVE = 'vich_uploader.pre_remove'; + const PRE_REMOVE = 'vich_uploader.pre_remove'; /** * Triggered after a file is removed. * * @Event("Vich\UploaderBundle\Event\Event") */ - const POST_REMOVE = 'vich_uploader.post_remove'; + const POST_REMOVE = 'vich_uploader.post_remove'; } diff --git a/EventListener/Doctrine/BaseListener.php b/EventListener/Doctrine/BaseListener.php index f5f655f8..2e234663 100644 --- a/EventListener/Doctrine/BaseListener.php +++ b/EventListener/Doctrine/BaseListener.php @@ -3,14 +3,13 @@ namespace Vich\UploaderBundle\EventListener\Doctrine; use Doctrine\Common\EventSubscriber; - use Vich\UploaderBundle\Adapter\AdapterInterface; use Vich\UploaderBundle\Handler\UploadHandler; use Vich\UploaderBundle\Metadata\MetadataReader; use Vich\UploaderBundle\Util\ClassUtils; /** - * BaseListener + * BaseListener. * * @author Kévin Gomez */ @@ -22,27 +21,27 @@ abstract class BaseListener implements EventSubscriber protected $mapping; /** - * @var AdapterInterface $adapter + * @var AdapterInterface */ protected $adapter; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; /** - * @var UploadHandler $handler + * @var UploadHandler */ protected $handler; /** * Constructs a new instance of UploaderListener. * - * @param string $mapping The mapping name. - * @param AdapterInterface $adapter The adapter. - * @param MetadataReader $metadata The metadata reader. - * @param UploadHandler $handler The upload handler. + * @param string $mapping The mapping name + * @param AdapterInterface $adapter The adapter + * @param MetadataReader $metadata The metadata reader + * @param UploadHandler $handler The upload handler */ public function __construct($mapping, AdapterInterface $adapter, MetadataReader $metadata, UploadHandler $handler) { @@ -55,7 +54,7 @@ public function __construct($mapping, AdapterInterface $adapter, MetadataReader /** * Checks if the given object is uploadable using the current mapping. * - * @param mixed $object The object to test. + * @param mixed $object The object to test * * @return bool */ @@ -67,15 +66,15 @@ protected function isUploadable($object) /** * Returns a list of uploadable fields for the given object and mapping. * - * @param mixed $object The object to use. + * @param mixed $object The object to use * - * @return array A list of field names. + * @return array A list of field names */ protected function getUploadableFields($object) { $fields = $this->metadata->getUploadableFields(ClassUtils::getClass($object), $this->mapping); - return array_map(function($data) { + return array_map(function ($data) { return $data['propertyName']; }, $fields); } diff --git a/EventListener/Doctrine/CleanListener.php b/EventListener/Doctrine/CleanListener.php index f3a33014..4d44b69f 100644 --- a/EventListener/Doctrine/CleanListener.php +++ b/EventListener/Doctrine/CleanListener.php @@ -5,7 +5,7 @@ use Doctrine\Common\EventArgs; /** - * CleanListener + * CleanListener. * * Listen to the update event to delete old files accordingly. * @@ -16,17 +16,17 @@ class CleanListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public function getSubscribedEvents() { - return array( + return [ 'preUpdate', - ); + ]; } /** - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function preUpdate(EventArgs $event) { diff --git a/EventListener/Doctrine/InjectListener.php b/EventListener/Doctrine/InjectListener.php index 766c771d..595b5b8a 100644 --- a/EventListener/Doctrine/InjectListener.php +++ b/EventListener/Doctrine/InjectListener.php @@ -5,7 +5,7 @@ use Doctrine\Common\EventArgs; /** - * InjectListener + * InjectListener. * * Listen to the load event in order to inject File objects. * @@ -16,17 +16,17 @@ class InjectListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public function getSubscribedEvents() { - return array( + return [ 'postLoad', - ); + ]; } /** - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function postLoad(EventArgs $event) { diff --git a/EventListener/Doctrine/RemoveListener.php b/EventListener/Doctrine/RemoveListener.php index 0912e1ab..f31849ae 100644 --- a/EventListener/Doctrine/RemoveListener.php +++ b/EventListener/Doctrine/RemoveListener.php @@ -6,7 +6,7 @@ use Doctrine\Common\Persistence\Proxy; /** - * RemoveListener + * RemoveListener. * * Listen to the remove event to delete files accordingly. * @@ -17,32 +17,32 @@ class RemoveListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public function getSubscribedEvents() { - return array( + return [ 'preRemove', 'postRemove', - ); + ]; } /** * Ensures a proxy will be usable in the postRemove. * - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function preRemove(EventArgs $event) { - $object = $this->adapter->getObjectFromArgs($event); + $object = $this->adapter->getObjectFromArgs($event); - if ($this->isUploadable($object) && $object instanceof Proxy) { - $object->__load(); - } + if ($this->isUploadable($object) && $object instanceof Proxy) { + $object->__load(); + } } /** - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function postRemove(EventArgs $event) { diff --git a/EventListener/Doctrine/UploadListener.php b/EventListener/Doctrine/UploadListener.php index 64c63643..f101cb88 100644 --- a/EventListener/Doctrine/UploadListener.php +++ b/EventListener/Doctrine/UploadListener.php @@ -5,7 +5,7 @@ use Doctrine\Common\EventArgs; /** - * UploadListener + * UploadListener. * * Handles file uploads. * @@ -16,18 +16,18 @@ class UploadListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public function getSubscribedEvents() { - return array( + return [ 'prePersist', 'preUpdate', - ); + ]; } /** - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function prePersist(EventArgs $event) { @@ -43,7 +43,7 @@ public function prePersist(EventArgs $event) } /** - * @param EventArgs $event The event. + * @param EventArgs $event The event */ public function preUpdate(EventArgs $event) { diff --git a/EventListener/Propel/BaseListener.php b/EventListener/Propel/BaseListener.php index 0b8c0deb..03da1469 100644 --- a/EventListener/Propel/BaseListener.php +++ b/EventListener/Propel/BaseListener.php @@ -3,14 +3,13 @@ namespace Vich\UploaderBundle\EventListener\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; - use Vich\UploaderBundle\Adapter\AdapterInterface; use Vich\UploaderBundle\Handler\UploadHandler; use Vich\UploaderBundle\Metadata\MetadataReader; use Vich\UploaderBundle\Util\ClassUtils; /** - * BaseListener + * BaseListener. * * @author Kévin Gomez */ @@ -22,27 +21,27 @@ abstract class BaseListener implements EventSubscriberInterface protected $mapping; /** - * @var AdapterInterface $adapter + * @var AdapterInterface */ protected $adapter; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; /** - * @var UploaderHandler $handler + * @var UploaderHandler */ protected $handler; /** * Constructs a new instance of BaseListener. * - * @param string $mapping The mapping name. - * @param AdapterInterface $adapter The adapter. - * @param MetadataReader $metadata The metadata reader. - * @param UploaderHandler $handler The upload handler. + * @param string $mapping The mapping name + * @param AdapterInterface $adapter The adapter + * @param MetadataReader $metadata The metadata reader + * @param UploaderHandler $handler The upload handler */ public function __construct($mapping, AdapterInterface $adapter, MetadataReader $metadata, UploadHandler $handler) { @@ -55,15 +54,15 @@ public function __construct($mapping, AdapterInterface $adapter, MetadataReader /** * Returns a list of uploadable fields for the given object and mapping. * - * @param mixed $object The object to use. + * @param mixed $object The object to use * - * @return array A list of field names. + * @return array A list of field names */ protected function getUploadableFields($object) { $fields = $this->metadata->getUploadableFields(ClassUtils::getClass($object), $this->mapping); - return array_map(function($data) { + return array_map(function ($data) { return $data['propertyName']; }, $fields); } diff --git a/EventListener/Propel/CleanListener.php b/EventListener/Propel/CleanListener.php index 816017ae..c18a2fec 100644 --- a/EventListener/Propel/CleanListener.php +++ b/EventListener/Propel/CleanListener.php @@ -5,7 +5,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; /** - * CleanListener + * CleanListener. * * Listen to the update event to delete old files accordingly. * @@ -16,17 +16,17 @@ class CleanListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public static function getSubscribedEvents() { - return array( + return [ 'propel.pre_update' => 'onUpload', - ); + ]; } /** - * @param GenericEvent $event The event. + * @param GenericEvent $event The event */ public function onUpload(GenericEvent $event) { diff --git a/EventListener/Propel/InjectListener.php b/EventListener/Propel/InjectListener.php index df6e1387..ab5e228d 100644 --- a/EventListener/Propel/InjectListener.php +++ b/EventListener/Propel/InjectListener.php @@ -5,7 +5,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; /** - * InjectListener + * InjectListener. * * Listen to the load event in order to inject File objects. * @@ -16,17 +16,17 @@ class InjectListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public static function getSubscribedEvents() { - return array( + return [ 'propel.post_hydrate' => 'onHydrate', - ); + ]; } /** - * @param GenericEvent $event The event. + * @param GenericEvent $event The event */ public function onHydrate(GenericEvent $event) { diff --git a/EventListener/Propel/RemoveListener.php b/EventListener/Propel/RemoveListener.php index 8016516c..b9ae46ee 100644 --- a/EventListener/Propel/RemoveListener.php +++ b/EventListener/Propel/RemoveListener.php @@ -5,7 +5,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; /** - * RemoveListener + * RemoveListener. * * Listen to the remove event to delete files accordingly. * @@ -16,17 +16,17 @@ class RemoveListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public static function getSubscribedEvents() { - return array( + return [ 'propel.post_delete' => 'onDelete', - ); + ]; } /** - * @param GenericEvent $event The event. + * @param GenericEvent $event The event */ public function onDelete(GenericEvent $event) { diff --git a/EventListener/Propel/UploadListener.php b/EventListener/Propel/UploadListener.php index 0474ef19..2c15374a 100644 --- a/EventListener/Propel/UploadListener.php +++ b/EventListener/Propel/UploadListener.php @@ -5,7 +5,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; /** - * UploadListener + * UploadListener. * * Handles file uploads. * @@ -16,18 +16,18 @@ class UploadListener extends BaseListener /** * The events the listener is subscribed to. * - * @return array The array of events. + * @return array The array of events */ public static function getSubscribedEvents() { - return array( + return [ 'propel.pre_insert' => 'onUpload', 'propel.pre_update' => 'onUpload', - ); + ]; } /** - * @param GenericEvent $event The event. + * @param GenericEvent $event The event */ public function onUpload(GenericEvent $event) { diff --git a/Exception/MappingNotFoundException.php b/Exception/MappingNotFoundException.php index 62aaff39..fee3495d 100644 --- a/Exception/MappingNotFoundException.php +++ b/Exception/MappingNotFoundException.php @@ -6,7 +6,7 @@ class MappingNotFoundException extends \RuntimeException { public static function createNotFoundForClassAndField($mapping, $class, $field) { - return new MappingNotFoundException( + 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) ); } diff --git a/Form/DataTransformer/FileTransformer.php b/Form/DataTransformer/FileTransformer.php index bd58cd02..a59e4d8e 100644 --- a/Form/DataTransformer/FileTransformer.php +++ b/Form/DataTransformer/FileTransformer.php @@ -8,9 +8,9 @@ class FileTransformer implements DataTransformerInterface { public function transform($file) { - return array( + return [ 'file' => $file, - ); + ]; } public function reverseTransform($data) diff --git a/Form/Type/VichFileType.php b/Form/Type/VichFileType.php index c545566e..b9e6d6c7 100644 --- a/Form/Type/VichFileType.php +++ b/Form/Type/VichFileType.php @@ -27,8 +27,8 @@ class VichFileType extends AbstractType protected $handler; /** - * @param StorageInterface $storage - * @param UploadHandler $handler + * @param StorageInterface $storage + * @param UploadHandler $handler */ public function __construct(StorageInterface $storage, UploadHandler $handler) { @@ -84,7 +84,7 @@ protected function buildDeleteField(FormBuilderInterface $builder, array $option } $form->add('delete', Type\CheckboxType::class, [ - 'label' => 'form.label.delete', + 'label' => 'form.label.delete', 'translation_domain' => 'VichUploaderBundle', 'required' => false, 'mapped' => false, diff --git a/Handler/AbstractHandler.php b/Handler/AbstractHandler.php index 9a7abacf..638cb34b 100644 --- a/Handler/AbstractHandler.php +++ b/Handler/AbstractHandler.php @@ -17,13 +17,13 @@ abstract class AbstractHandler protected $factory; /** - * @var StorageInterface $storage + * @var StorageInterface */ protected $storage; /** - * @param PropertyMappingFactory $factory The mapping factory. - * @param StorageInterface $storage The storage. + * @param PropertyMappingFactory $factory The mapping factory + * @param StorageInterface $storage The storage */ public function __construct(PropertyMappingFactory $factory, StorageInterface $storage) { diff --git a/Handler/DownloadHandler.php b/Handler/DownloadHandler.php index 802e2ff7..b7718b21 100644 --- a/Handler/DownloadHandler.php +++ b/Handler/DownloadHandler.php @@ -4,7 +4,6 @@ use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\StreamedResponse; - use Vich\UploaderBundle\Exception\NoFileFoundException; use Vich\UploaderBundle\Util\Transliterator; @@ -28,7 +27,7 @@ class DownloadHandler extends AbstractHandler public function downloadObject($object, $field, $className = null, $fileName = null) { $mapping = $this->getMapping($object, $field, $className); - $stream = $this->storage->resolveStream($object, $field, $className); + $stream = $this->storage->resolveStream($object, $field, $className); if ($stream === null) { throw new NoFileFoundException(sprintf('No file found in field "%s".', $field)); diff --git a/Handler/UploadHandler.php b/Handler/UploadHandler.php index 507f347f..3bac446c 100644 --- a/Handler/UploadHandler.php +++ b/Handler/UploadHandler.php @@ -19,22 +19,22 @@ class UploadHandler extends AbstractHandler { /** - * @var FileInjectorInterface $injector + * @var FileInjectorInterface */ protected $injector; /** - * @var EventDispatcherInterface $dispatcher + * @var EventDispatcherInterface */ protected $dispatcher; /** * Constructs a new instance of UploaderListener. * - * @param PropertyMappingFactory $factory The mapping factory. - * @param StorageInterface $storage The storage. - * @param FileInjectorInterface $injector The injector. - * @param EventDispatcherInterface $dispatcher The event dispatcher. + * @param PropertyMappingFactory $factory The mapping factory + * @param StorageInterface $storage The storage + * @param FileInjectorInterface $injector The injector + * @param EventDispatcherInterface $dispatcher The event dispatcher */ public function __construct(PropertyMappingFactory $factory, StorageInterface $storage, FileInjectorInterface $injector, EventDispatcherInterface $dispatcher) { @@ -47,8 +47,8 @@ public function __construct(PropertyMappingFactory $factory, StorageInterface $s /** * Checks for file to upload. * - * @param object $obj The object. - * @param string $fieldName The name of the field containing the upload (has to be mapped). + * @param object $obj The object + * @param string $fieldName The name of the field containing the upload (has to be mapped) */ public function upload($obj, $fieldName) { diff --git a/Injector/FileInjector.php b/Injector/FileInjector.php index 55a41217..3175103b 100644 --- a/Injector/FileInjector.php +++ b/Injector/FileInjector.php @@ -3,7 +3,6 @@ namespace Vich\UploaderBundle\Injector; use Symfony\Component\HttpFoundation\File\File; - use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Storage\StorageInterface; @@ -22,7 +21,7 @@ class FileInjector implements FileInjectorInterface /** * Constructs a new instance of FileInjector. * - * @param StorageInterface $storage Storage. + * @param StorageInterface $storage Storage */ public function __construct(StorageInterface $storage) { @@ -30,7 +29,7 @@ public function __construct(StorageInterface $storage) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function injectFile($obj, PropertyMapping $mapping) { diff --git a/Injector/FileInjectorInterface.php b/Injector/FileInjectorInterface.php index 163ee9a1..115591f5 100644 --- a/Injector/FileInjectorInterface.php +++ b/Injector/FileInjectorInterface.php @@ -17,8 +17,8 @@ interface FileInjectorInterface * The field is populated with a \Symfony\Component\HttpFoundation\File\File * instance. * - * @param object $obj The object. - * @param PropertyMapping $mapping The mapping representing the field to populate. + * @param object $obj The object + * @param PropertyMapping $mapping The mapping representing the field to populate */ public function injectFile($obj, PropertyMapping $mapping); } diff --git a/Mapping/Annotation/UploadableField.php b/Mapping/Annotation/UploadableField.php index bce19a85..2b2536f8 100644 --- a/Mapping/Annotation/UploadableField.php +++ b/Mapping/Annotation/UploadableField.php @@ -13,19 +13,20 @@ class UploadableField { /** - * @var string $mapping + * @var string */ protected $mapping; /** - * @var string $fileNameProperty + * @var string */ protected $fileNameProperty; /** * Constructs a new instance of UploadableField. * - * @param array $options The options. + * @param array $options The options + * * @throws \InvalidArgumentException */ public function __construct(array $options) @@ -44,7 +45,7 @@ public function __construct(array $options) /** * Gets the mapping name. * - * @return string The mapping name. + * @return string The mapping name */ public function getMapping() { @@ -54,7 +55,7 @@ public function getMapping() /** * Gets the file name property. * - * @return string The file name property. + * @return string The file name property */ public function getFileNameProperty() { diff --git a/Mapping/PropertyMapping.php b/Mapping/PropertyMapping.php index 95bbc572..e3f6732b 100644 --- a/Mapping/PropertyMapping.php +++ b/Mapping/PropertyMapping.php @@ -4,7 +4,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\PropertyAccess\PropertyAccess; - use Vich\UploaderBundle\Naming\DirectoryNamerInterface; use Vich\UploaderBundle\Naming\NamerInterface; @@ -16,43 +15,43 @@ class PropertyMapping { /** - * @var NamerInterface $namer + * @var NamerInterface */ protected $namer; /** - * @var DirectoryNamerInterface $directoryNamer + * @var DirectoryNamerInterface */ protected $directoryNamer; /** - * @var array $mapping + * @var array */ protected $mapping; /** - * @var string $mappingName + * @var string */ protected $mappingName; /** - * @var string $filePropertyPath + * @var string */ protected $filePropertyPath; /** - * @var string $fileNamePropertyPath + * @var string */ protected $fileNamePropertyPath; /** - * @var PropertyAccess $accessor + * @var PropertyAccess */ protected $accessor; /** - * @param string $filePropertyPath The path to the "file" property. - * @param string $fileNamePropertyPath The path to the "filename" property. + * @param string $filePropertyPath The path to the "file" property + * @param string $fileNamePropertyPath The path to the "filename" property */ public function __construct($filePropertyPath, $fileNamePropertyPath) { @@ -63,8 +62,9 @@ public function __construct($filePropertyPath, $fileNamePropertyPath) /** * Gets the file property value for the given object. * - * @param object $obj The object. - * @return UploadedFile The file. + * @param object $obj The object + * + * @return UploadedFile The file */ public function getFile($obj) { @@ -76,8 +76,8 @@ public function getFile($obj) /** * Modifies the file property value for the given object. * - * @param object $obj The object. - * @param UploadedFile $file The new file. + * @param object $obj The object + * @param UploadedFile $file The new file */ public function setFile($obj, $file) { @@ -88,9 +88,9 @@ public function setFile($obj, $file) /** * Gets the fileName property of the given object. * - * @param object $obj The object. + * @param object $obj The object * - * @return string The filename. + * @return string The filename */ public function getFileName($obj) { @@ -102,7 +102,7 @@ public function getFileName($obj) /** * Modifies the fileName property of the given object. * - * @param object $obj The object. + * @param object $obj The object * @param $value */ public function setFileName($obj, $value) @@ -114,7 +114,7 @@ public function setFileName($obj, $value) /** * Gets the configured file property name. * - * @return string The name. + * @return string The name */ public function getFilePropertyName() { @@ -124,7 +124,7 @@ public function getFilePropertyName() /** * Gets the configured filename property name. * - * @return string The name. + * @return string The name */ public function getFileNamePropertyName() { @@ -134,7 +134,7 @@ public function getFileNamePropertyName() /** * Gets the configured namer. * - * @return null|NamerInterface The namer. + * @return null|NamerInterface The namer */ public function getNamer() { @@ -144,7 +144,7 @@ public function getNamer() /** * Sets the namer. * - * @param NamerInterface $namer The namer. + * @param NamerInterface $namer The namer */ public function setNamer(NamerInterface $namer) { @@ -154,7 +154,7 @@ public function setNamer(NamerInterface $namer) /** * Determines if the mapping has a custom namer configured. * - * @return bool True if has namer, false otherwise. + * @return bool True if has namer, false otherwise */ public function hasNamer() { @@ -164,7 +164,7 @@ public function hasNamer() /** * Gets the configured directory namer. * - * @return null|\Vich\UploaderBundle\Naming\DirectoryNamerInterface The directory namer. + * @return null|\Vich\UploaderBundle\Naming\DirectoryNamerInterface The directory namer */ public function getDirectoryNamer() { @@ -174,7 +174,7 @@ public function getDirectoryNamer() /** * Sets the directory namer. * - * @param \Vich\UploaderBundle\Naming\DirectoryNamerInterface $directoryNamer The directory namer. + * @param \Vich\UploaderBundle\Naming\DirectoryNamerInterface $directoryNamer The directory namer */ public function setDirectoryNamer(DirectoryNamerInterface $directoryNamer) { @@ -184,7 +184,7 @@ public function setDirectoryNamer(DirectoryNamerInterface $directoryNamer) /** * Determines if the mapping has a custom directory namer configured. * - * @return bool True if has directory namer, false otherwise. + * @return bool True if has directory namer, false otherwise */ public function hasDirectoryNamer() { @@ -204,7 +204,7 @@ public function setMapping(array $mapping) /** * Gets the configured configuration mapping name. * - * @return string The mapping name. + * @return string The mapping name */ public function getMappingName() { @@ -214,7 +214,7 @@ public function getMappingName() /** * Sets the configured configuration mapping name. * - * @param string $mappingName The mapping name. + * @param string $mappingName The mapping name */ public function setMappingName($mappingName) { @@ -226,7 +226,7 @@ public function setMappingName($mappingName) * * @param object $obj * - * @return string The upload directory. + * @return string The upload directory */ public function getUploadDir($obj) { @@ -245,7 +245,7 @@ public function getUploadDir($obj) /** * Gets the base upload directory. * - * @return string The configured upload directory. + * @return string The configured upload directory */ public function getUploadDestination() { @@ -253,7 +253,7 @@ public function getUploadDestination() } /** - * Get uri prefix + * Get uri prefix. * * @return string */ @@ -268,10 +268,10 @@ public function getUriPrefix() * Ie: if the given object is in fact an array, the property path must * look like [myPath]. * - * @param object|array $object The object to inspect. - * @param string $propertyPath The property path to fix. + * @param object|array $object The object to inspect + * @param string $propertyPath The property path to fix * - * @return string The fixed property path. + * @return string The fixed property path */ protected function fixPropertyPath($object, $propertyPath) { diff --git a/Mapping/PropertyMappingFactory.php b/Mapping/PropertyMappingFactory.php index 279a8e52..0dcdb293 100644 --- a/Mapping/PropertyMappingFactory.php +++ b/Mapping/PropertyMappingFactory.php @@ -4,7 +4,6 @@ use Doctrine\Common\Persistence\Proxy; use Symfony\Component\DependencyInjection\ContainerInterface; - use Vich\UploaderBundle\Exception\MappingNotFoundException; use Vich\UploaderBundle\Exception\NotUploadableException; use Vich\UploaderBundle\Metadata\MetadataReader; @@ -19,32 +18,32 @@ class PropertyMappingFactory { /** - * @var ContainerInterface $container + * @var ContainerInterface */ protected $container; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; /** - * @var array $mappings + * @var array */ protected $mappings; /** - * @var string $defaultFilenameAttributeSuffix + * @var string */ protected $defaultFilenameAttributeSuffix; /** * Constructs a new instance of PropertyMappingFactory. * - * @param ContainerInterface $container The container. - * @param MetadataReader $metadata The mapping mapping. - * @param array $mappings The configured mappings. - * @param string $defaultFilenameAttributeSuffix The default suffix to be used if the fileNamePropertyPath isn't given for a mapping. + * @param ContainerInterface $container The container + * @param MetadataReader $metadata The mapping mapping + * @param array $mappings The configured mappings + * @param string $defaultFilenameAttributeSuffix The default suffix to be used if the fileNamePropertyPath isn't given for a mapping */ public function __construct(ContainerInterface $container, MetadataReader $metadata, array $mappings, $defaultFilenameAttributeSuffix = '_name') { @@ -59,10 +58,10 @@ public function __construct(ContainerInterface $container, MetadataReader $metad * configuration for the uploadable fields in the specified * object. * - * @param object $obj The object. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return array An array up PropertyMapping objects. + * @return array An array up PropertyMapping objects */ public function fromObject($obj, $className = null, $mappingName = null) { @@ -73,7 +72,7 @@ public function fromObject($obj, $className = null, $mappingName = null) $class = $this->getClassName($obj, $className); $this->checkUploadable($class); - $mappings = array(); + $mappings = []; foreach ($this->metadata->getUploadableFields($class) as $field => $mappingData) { if ($mappingName !== null && $mappingName !== $mappingData['mapping']) { continue; @@ -89,11 +88,11 @@ public function fromObject($obj, $className = null, $mappingName = null) * Creates a property mapping object which contains the * configuration for the specified uploadable field. * - * @param object $obj The object. - * @param string $field The field. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $field The field + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return null|PropertyMapping The property mapping. + * @return null|PropertyMapping The property mapping */ public function fromField($obj, $field, $className = null) { @@ -115,7 +114,7 @@ public function fromField($obj, $field, $className = null) /** * Checks to see if the class is uploadable. * - * @param string $class The class name (FQCN). + * @param string $class The class name (FQCN) * * @throws NotUploadableException */ @@ -129,11 +128,12 @@ protected function checkUploadable($class) /** * Creates the property mapping from the read annotation and configured mapping. * - * @param object $obj The object. - * @param string $fieldName The field name. - * @param array $mappingData The mapping data. + * @param object $obj The object + * @param string $fieldName The field name + * @param array $mappingData The mapping data + * + * @return PropertyMapping The property mapping * - * @return PropertyMapping The property mapping. * @throws MappingNotFoundException */ protected function createMapping($obj, $fieldName, array $mappingData) @@ -144,7 +144,7 @@ protected function createMapping($obj, $fieldName, array $mappingData) $config = $this->mappings[$mappingData['mapping']]; $fileProperty = isset($mappingData['propertyName']) ? $mappingData['propertyName'] : $fieldName; - $fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty . $this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty']; + $fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty.$this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty']; $mapping = new PropertyMapping($fileProperty, $fileNameProperty); $mapping->setMappingName($mappingData['mapping']); @@ -184,10 +184,11 @@ protected function createMapping($obj, $fieldName, array $mappingData) /** * Returns the className of the given object. * - * @param object $object The object to inspect. - * @param string $className User specified className. + * @param object $object The object to inspect + * @param string $className User specified className * * @return string + * * @throws \RuntimeException */ protected function getClassName($object, $className = null) diff --git a/Metadata/ClassMetadata.php b/Metadata/ClassMetadata.php index 2caa4896..12d5bf4c 100644 --- a/Metadata/ClassMetadata.php +++ b/Metadata/ClassMetadata.php @@ -6,18 +6,18 @@ class ClassMetadata extends BaseClassMetadata { - public $fields = array(); + public $fields = []; public function serialize() { - return serialize(array( + return serialize([ $this->name, $this->methodMetadata, $this->propertyMetadata, $this->fileResources, $this->createdAt, - $this->fields - )); + $this->fields, + ]); } public function unserialize($str) diff --git a/Metadata/Driver/AbstractFileDriver.php b/Metadata/Driver/AbstractFileDriver.php index 00c63c3a..f6d67ace 100644 --- a/Metadata/Driver/AbstractFileDriver.php +++ b/Metadata/Driver/AbstractFileDriver.php @@ -33,7 +33,7 @@ public function loadMetadataForClass(\ReflectionClass $class) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getAllClassNames() { @@ -41,7 +41,7 @@ public function getAllClassNames() throw new \RuntimeException('Locator "%s" must be an instance of "AdvancedFileLocatorInterface".'); } - $classNames = array(); + $classNames = []; foreach ($this->locator->findAllClasses($this->getExtension()) as $file) { $classNames[] = $this->getClassNameFromFile($file->getRealpath()); } diff --git a/Metadata/Driver/AnnotationDriver.php b/Metadata/Driver/AnnotationDriver.php index 77ba47f7..27d00393 100644 --- a/Metadata/Driver/AnnotationDriver.php +++ b/Metadata/Driver/AnnotationDriver.php @@ -4,18 +4,17 @@ use Doctrine\Common\Annotations\Reader as AnnotationReader; use Metadata\Driver\DriverInterface; - use Vich\UploaderBundle\Metadata\ClassMetadata; /** - * Annotation driver + * Annotation driver. * * @author Kévin Gomez */ class AnnotationDriver implements DriverInterface { - const UPLOADABLE_ANNOTATION = 'Vich\UploaderBundle\Mapping\Annotation\Uploadable'; - const UPLOADABLE_FIELD_ANNOTATION = 'Vich\UploaderBundle\Mapping\Annotation\UploadableField'; + const UPLOADABLE_ANNOTATION = 'Vich\UploaderBundle\Mapping\Annotation\Uploadable'; + const UPLOADABLE_FIELD_ANNOTATION = 'Vich\UploaderBundle\Mapping\Annotation\UploadableField'; protected $reader; @@ -38,11 +37,11 @@ public function loadMetadataForClass(\ReflectionClass $class) continue; } - $fieldMetadata = array( - 'mapping' => $uploadableField->getMapping(), - 'propertyName' => $property->getName(), - 'fileNameProperty' => $uploadableField->getFileNameProperty(), - ); + $fieldMetadata = [ + 'mapping' => $uploadableField->getMapping(), + 'propertyName' => $property->getName(), + 'fileNameProperty' => $uploadableField->getFileNameProperty(), + ]; $metadata->fields[$property->getName()] = $fieldMetadata; } diff --git a/Metadata/Driver/ChainDriver.php b/Metadata/Driver/ChainDriver.php index 11956005..c1342d5f 100644 --- a/Metadata/Driver/ChainDriver.php +++ b/Metadata/Driver/ChainDriver.php @@ -9,7 +9,7 @@ class ChainDriver implements AdvancedDriverInterface { protected $drivers; - public function __construct(array $drivers = array()) + public function __construct(array $drivers = []) { $this->drivers = $drivers; } @@ -31,11 +31,11 @@ public function loadMetadataForClass(\ReflectionClass $class) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getAllClassNames() { - $classes = array(); + $classes = []; foreach ($this->drivers as $driver) { if (!$driver instanceof AdvancedDriverInterface) { continue; diff --git a/Metadata/Driver/FileLocator.php b/Metadata/Driver/FileLocator.php index 212d2412..0d303ff5 100644 --- a/Metadata/Driver/FileLocator.php +++ b/Metadata/Driver/FileLocator.php @@ -58,7 +58,7 @@ public function findFileForClass(\ReflectionClass $class, $extension) public function findAllClasses($extension) { if (empty($this->dirs)) { - return array(); + return []; } $files = Finder::create() diff --git a/Metadata/Driver/XmlDriver.php b/Metadata/Driver/XmlDriver.php index 9facd4d8..d634a416 100644 --- a/Metadata/Driver/XmlDriver.php +++ b/Metadata/Driver/XmlDriver.php @@ -5,7 +5,7 @@ use Vich\UploaderBundle\Metadata\ClassMetadata; /** - * Xml driver + * Xml driver. * * @author Kévin Gomez */ @@ -19,11 +19,11 @@ protected function loadMetadataFromFile($file, \ReflectionClass $class = null) $metadata = new ClassMetadata($className); foreach ($elem->children() as $field) { - $fieldMetadata = array( - 'mapping' => (string) $field->attributes()->mapping, - 'propertyName' => (string) $field->attributes()->name, - 'fileNameProperty' => (string) $field->attributes()->filename_property, - ); + $fieldMetadata = [ + 'mapping' => (string) $field->attributes()->mapping, + 'propertyName' => (string) $field->attributes()->name, + 'fileNameProperty' => (string) $field->attributes()->filename_property, + ]; $metadata->fields[(string) $field->attributes()->name] = $fieldMetadata; } @@ -50,7 +50,7 @@ protected function loadMappingFile($file) } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getExtension() { diff --git a/Metadata/Driver/YamlDriver.php b/Metadata/Driver/YamlDriver.php index 9e9498f6..19549c16 100644 --- a/Metadata/Driver/YamlDriver.php +++ b/Metadata/Driver/YamlDriver.php @@ -3,18 +3,17 @@ namespace Vich\UploaderBundle\Metadata\Driver; use Symfony\Component\Yaml\Yaml as YmlParser; - use Vich\UploaderBundle\Metadata\ClassMetadata; /** - * Yaml driver + * Yaml driver. * * @author Kévin Gomez */ class YamlDriver extends AbstractFileDriver { /** - * {@inheritDoc} + * {@inheritdoc} */ protected function loadMetadataFromFile($file, \ReflectionClass $class = null) { @@ -23,11 +22,11 @@ protected function loadMetadataFromFile($file, \ReflectionClass $class = null) $metadata = new ClassMetadata($className); foreach ($config[$className] as $field => $mappingData) { - $fieldMetadata = array( - 'mapping' => $mappingData['mapping'], - 'propertyName' => $field, - 'fileNameProperty' => isset($mappingData['filename_property']) ? $mappingData['filename_property'] : null, - ); + $fieldMetadata = [ + 'mapping' => $mappingData['mapping'], + 'propertyName' => $field, + 'fileNameProperty' => isset($mappingData['filename_property']) ? $mappingData['filename_property'] : null, + ]; $metadata->fields[$field] = $fieldMetadata; } @@ -46,7 +45,7 @@ protected function loadMappingFile($file) } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getExtension() { diff --git a/Metadata/MetadataReader.php b/Metadata/MetadataReader.php index 0cb01641..a512f6e4 100644 --- a/Metadata/MetadataReader.php +++ b/Metadata/MetadataReader.php @@ -14,14 +14,14 @@ class MetadataReader { /** - * @var AdvancedMetadataFactoryInterface $reader + * @var AdvancedMetadataFactoryInterface */ protected $reader; /** * Constructs a new instance of the MetadataReader. * - * @param AdvancedMetadataFactoryInterface $reader The "low-level" metadata reader. + * @param AdvancedMetadataFactoryInterface $reader The "low-level" metadata reader */ public function __construct(AdvancedMetadataFactoryInterface $reader) { @@ -31,8 +31,8 @@ public function __construct(AdvancedMetadataFactoryInterface $reader) /** * Tells if the given class is uploadable. * - * @param string $class The class name to test (FQCN). - * @param string $mapping If given, also checks that the object has the given mapping. + * @param string $class The class name to test (FQCN) + * @param string $mapping If given, also checks that the object has the given mapping * * @return bool */ @@ -58,7 +58,7 @@ public function isUploadable($class, $mapping = null) /** * Search for all uploadable classes. * - * @return array A list of uploadable class names. + * @return array A list of uploadable class names */ public function getUploadableClasses() { @@ -68,14 +68,14 @@ public function getUploadableClasses() /** * Attempts to read the uploadable fields. * - * @param string $class The class name to test (FQCN). + * @param string $class The class name to test (FQCN) * - * @return array A list of uploadable fields. + * @return array A list of uploadable fields */ public function getUploadableFields($class) { $metadata = $this->reader->getMetadataForClass($class); - $uploadableFields = array(); + $uploadableFields = []; foreach ($metadata->classMetadata as $classMetadata) { $uploadableFields = array_merge($uploadableFields, $classMetadata->fields); @@ -87,10 +87,10 @@ public function getUploadableFields($class) /** * Attempts to read the mapping of a specified property. * - * @param string $class The class name to test (FQCN). + * @param string $class The class name to test (FQCN) * @param string $field The field * - * @return null|array The field mapping. + * @return null|array The field mapping */ public function getUploadableField($class, $field) { diff --git a/Naming/ConfigurableInterface.php b/Naming/ConfigurableInterface.php index 0c13d0c0..5ba9177d 100644 --- a/Naming/ConfigurableInterface.php +++ b/Naming/ConfigurableInterface.php @@ -14,7 +14,7 @@ interface ConfigurableInterface /** * Injects configuration options. * - * @param array $options The options. + * @param array $options The options */ public function configure(array $options); } diff --git a/Naming/DirectoryNamerInterface.php b/Naming/DirectoryNamerInterface.php index 66d293b2..d49b3f17 100644 --- a/Naming/DirectoryNamerInterface.php +++ b/Naming/DirectoryNamerInterface.php @@ -14,10 +14,10 @@ interface DirectoryNamerInterface /** * Creates a directory name for the file being uploaded. * - * @param object $object The object the upload is attached to. - * @param PropertyMapping $mapping The mapping to use to manipulate the given object. + * @param object $object The object the upload is attached to + * @param PropertyMapping $mapping The mapping to use to manipulate the given object * - * @return string The directory name. + * @return string The directory name */ public function directoryName($object, PropertyMapping $mapping); } diff --git a/Naming/HashNamer.php b/Naming/HashNamer.php index 9ca66392..7fd0ffbb 100644 --- a/Naming/HashNamer.php +++ b/Naming/HashNamer.php @@ -16,12 +16,12 @@ class HashNamer implements NamerInterface, ConfigurableInterface /** * @param array $options Options for this namer. The following options are accepted: - * - algorithm: wich hash algorithm to use. - * - length: limit file name length. + * - algorithm: wich hash algorithm to use. + * - length: limit file name length */ public function configure(array $options) { - $options = array_merge(array('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']; diff --git a/Naming/NamerInterface.php b/Naming/NamerInterface.php index 3ee49f66..92006f22 100644 --- a/Naming/NamerInterface.php +++ b/Naming/NamerInterface.php @@ -14,10 +14,10 @@ interface NamerInterface /** * Creates a name for the file being uploaded. * - * @param object $object The object the upload is attached to. - * @param PropertyMapping $mapping The mapping to use to manipulate the given object. + * @param object $object The object the upload is attached to + * @param PropertyMapping $mapping The mapping to use to manipulate the given object * - * @return string The file name. + * @return string The file name */ public function name($object, PropertyMapping $mapping); } diff --git a/Naming/OrignameNamer.php b/Naming/OrignameNamer.php index d39360e0..bdb61cb9 100644 --- a/Naming/OrignameNamer.php +++ b/Naming/OrignameNamer.php @@ -3,12 +3,11 @@ namespace Vich\UploaderBundle\Naming; use Symfony\Component\HttpFoundation\File\UploadedFile; - use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Util\Transliterator; /** - * OrignameNamer + * OrignameNamer. * * @author Ivan Borzenkov */ @@ -21,7 +20,7 @@ class OrignameNamer implements NamerInterface, ConfigurableInterface /** * @param array $options Options for this namer. The following options are accepted: - * - transliterate: whether the filename should be transliterated or not. + * - transliterate: whether the filename should be transliterated or not */ public function configure(array $options) { @@ -29,7 +28,7 @@ public function configure(array $options) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function name($object, PropertyMapping $mapping) { @@ -40,7 +39,7 @@ public function name($object, PropertyMapping $mapping) $name = Transliterator::transliterate($name); } - /** @var $file UploadedFile */ + /* @var $file UploadedFile */ return uniqid().'_'.$name; } diff --git a/Naming/PropertyNamer.php b/Naming/PropertyNamer.php index 398dac72..5eeec9ed 100644 --- a/Naming/PropertyNamer.php +++ b/Naming/PropertyNamer.php @@ -4,13 +4,12 @@ use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; - use Vich\UploaderBundle\Exception\NameGenerationException; use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Util\Transliterator; /** - * PropertyNamer + * PropertyNamer. * * @author Kévin Gomez */ @@ -30,8 +29,8 @@ class PropertyNamer implements NamerInterface, ConfigurableInterface /** * @param array $options Options for this namer. The following options are accepted: - * - property: path to the property used to name the file. Can be either an attribute or a method. - * - transliterate: whether the filename should be transliterated or not. + * - property: path to the property used to name the file. Can be either an attribute or a method. + * - transliterate: whether the filename should be transliterated or not */ public function configure(array $options) { @@ -44,7 +43,7 @@ public function configure(array $options) } /** - * @inheritDoc + * {@inheritdoc} */ public function name($object, PropertyMapping $mapping) { diff --git a/Naming/SubdirDirectoryNamer.php b/Naming/SubdirDirectoryNamer.php index 27bf7dea..22a2a655 100644 --- a/Naming/SubdirDirectoryNamer.php +++ b/Naming/SubdirDirectoryNamer.php @@ -16,12 +16,12 @@ class SubdirDirectoryNamer implements DirectoryNamerInterface, ConfigurableInter /** * @param array $options Options for this namer. The following options are accepted: - * - chars_per_dir: how many chars use for each dir. - * - dirs: how many dirs create. + * - chars_per_dir: how many chars use for each dir. + * - dirs: how many dirs create */ public function configure(array $options) { - $options = array_merge(array('chars_per_dir' => $this->charsPerDir, 'dirs' => $this->dirs), $options); + $options = array_merge(['chars_per_dir' => $this->charsPerDir, 'dirs' => $this->dirs], $options); $this->charsPerDir = $options['chars_per_dir']; $this->dirs = $options['dirs']; @@ -34,7 +34,7 @@ public function directoryName($object, PropertyMapping $mapping) { $fileName = $mapping->getFileName($object); - $parts = array(); + $parts = []; for ($i = 0, $start = 0; $i < $this->dirs; $i++, $start += $this->charsPerDir) { $parts[] = substr($fileName, $start, $this->charsPerDir); } diff --git a/Naming/UniqidNamer.php b/Naming/UniqidNamer.php index 1f2044fd..aeac43eb 100644 --- a/Naming/UniqidNamer.php +++ b/Naming/UniqidNamer.php @@ -5,7 +5,7 @@ use Vich\UploaderBundle\Mapping\PropertyMapping; /** - * UniqidNamer + * UniqidNamer. * * @author Emmanuel Vella */ @@ -14,7 +14,7 @@ class UniqidNamer implements NamerInterface use Polyfill\FileExtensionTrait; /** - * {@inheritDoc} + * {@inheritdoc} */ public function name($object, PropertyMapping $mapping) { diff --git a/Storage/AbstractStorage.php b/Storage/AbstractStorage.php index 27aee808..eb062a14 100644 --- a/Storage/AbstractStorage.php +++ b/Storage/AbstractStorage.php @@ -15,14 +15,14 @@ abstract class AbstractStorage implements StorageInterface { /** - * @var PropertyMappingFactory $factory + * @var PropertyMappingFactory */ protected $factory; /** * Constructs a new instance of FileSystemStorage. * - * @param PropertyMappingFactory $factory The factory. + * @param PropertyMappingFactory $factory The factory */ public function __construct(PropertyMappingFactory $factory) { @@ -30,19 +30,19 @@ public function __construct(PropertyMappingFactory $factory) } /** - * Do real upload + * Do real upload. * * @param PropertyMapping $mapping * @param UploadedFile $file * @param string $dir * @param string $name * - * @return boolean + * @return bool */ abstract protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name); /** - * {@inheritDoc} + * {@inheritdoc} */ public function upload($obj, PropertyMapping $mapping) { @@ -68,18 +68,18 @@ public function upload($obj, PropertyMapping $mapping) } /** - * Do real remove + * Do real remove. * * @param PropertyMapping $mapping * @param string $dir * @param string $name * - * @return boolean + * @return bool */ abstract protected function doRemove(PropertyMapping $mapping, $dir, $name); /** - * {@inheritDoc} + * {@inheritdoc} */ public function remove($obj, PropertyMapping $mapping) { @@ -93,19 +93,19 @@ public function remove($obj, PropertyMapping $mapping) } /** - * Do resolve path + * Do resolve path. * - * @param PropertyMapping $mapping The mapping representing the field. - * @param string $dir The directory in which the file is uploaded. - * @param string $name The file name. - * @param bool $relative Whether the path should be relative or absolute. + * @param PropertyMapping $mapping The mapping representing the field + * @param string $dir The directory in which the file is uploaded + * @param string $name The file name + * @param bool $relative Whether the path should be relative or absolute * * @return string */ abstract protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relative = false); /** - * {@inheritDoc} + * {@inheritdoc} */ public function resolvePath($obj, $fieldName, $className = null, $relative = false) { @@ -119,7 +119,7 @@ public function resolvePath($obj, $fieldName, $className = null, $relative = fal } /** - * {@inheritDoc} + * {@inheritdoc} */ public function resolveUri($obj, $fieldName, $className = null) { @@ -136,7 +136,7 @@ public function resolveUri($obj, $fieldName, $className = null) } /** - * {@inheritDoc} + * {@inheritdoc} */ public function resolveStream($obj, $fieldName, $className = null) { @@ -160,6 +160,6 @@ protected function getFilename($obj, $fieldName, $className = null) throw new MappingNotFoundException(sprintf('Mapping not found for field "%s"', $fieldName)); } - return array($mapping, $mapping->getFileName($obj)); + return [$mapping, $mapping->getFileName($obj)]; } } diff --git a/Storage/FileSystemStorage.php b/Storage/FileSystemStorage.php index 7860f681..a316722b 100644 --- a/Storage/FileSystemStorage.php +++ b/Storage/FileSystemStorage.php @@ -13,7 +13,7 @@ class FileSystemStorage extends AbstractStorage { /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name) { @@ -23,7 +23,7 @@ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doRemove(PropertyMapping $mapping, $dir, $name) { @@ -33,7 +33,7 @@ protected function doRemove(PropertyMapping $mapping, $dir, $name) } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relative = false) { @@ -47,7 +47,7 @@ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relativ } /** - * {@inheritDoc} + * {@inheritdoc} */ public function resolveUri($obj, $mappingName, $className = null) { diff --git a/Storage/FlysystemStorage.php b/Storage/FlysystemStorage.php index fc97c81a..a22e0ae1 100644 --- a/Storage/FlysystemStorage.php +++ b/Storage/FlysystemStorage.php @@ -22,8 +22,8 @@ class FlysystemStorage extends AbstractStorage /** * Constructs a new instance of FlysystemStorage. * - * @param PropertyMappingFactory $factory The factory. - * @param MountManager $mountManager Gaufrete filesystem factory. + * @param PropertyMappingFactory $factory The factory + * @param MountManager $mountManager Gaufrete filesystem factory */ public function __construct(PropertyMappingFactory $factory, MountManager $mountManager) { @@ -33,7 +33,7 @@ public function __construct(PropertyMappingFactory $factory, MountManager $mount } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name) { @@ -41,13 +41,13 @@ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $path = !empty($dir) ? $dir.'/'.$name : $name; $stream = fopen($file->getRealPath(), 'r'); - $fs->writeStream($path, $stream, array( + $fs->writeStream($path, $stream, [ 'mimetype' => $file->getMimeType(), - )); + ]); } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doRemove(PropertyMapping $mapping, $dir, $name) { @@ -62,7 +62,7 @@ protected function doRemove(PropertyMapping $mapping, $dir, $name) } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relative = false) { @@ -77,7 +77,7 @@ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relativ } /** - * {@inheritDoc} + * {@inheritdoc} */ public function resolveStream($obj, $fieldName, $className = null) { @@ -94,7 +94,7 @@ public function resolveStream($obj, $fieldName, $className = null) } /** - * Get filesystem adapter by key + * Get filesystem adapter by key. * * @param string $key * diff --git a/Storage/GaufretteStorage.php b/Storage/GaufretteStorage.php index a5c76ea7..7d907033 100644 --- a/Storage/GaufretteStorage.php +++ b/Storage/GaufretteStorage.php @@ -30,20 +30,20 @@ class GaufretteStorage extends AbstractStorage /** * Constructs a new instance of FileSystemStorage. * - * @param PropertyMappingFactory $factory The factory. - * @param FilesystemMap $filesystemMap Gaufrete filesystem factory. - * @param string $protocol Gaufrette stream wrapper protocol. + * @param PropertyMappingFactory $factory The factory + * @param FilesystemMap $filesystemMap Gaufrete filesystem factory + * @param string $protocol Gaufrette stream wrapper protocol */ public function __construct(PropertyMappingFactory $factory, FilesystemMap $filesystemMap, $protocol = 'gaufrette') { parent::__construct($factory); $this->filesystemMap = $filesystemMap; - $this->protocol = $protocol; + $this->protocol = $protocol; } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name) { @@ -51,14 +51,14 @@ protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $path = !empty($dir) ? $dir.'/'.$name : $name; if ($filesystem->getAdapter() instanceof MetadataSupporter) { - $filesystem->getAdapter()->setMetadata($path, array('contentType' => $file->getMimeType())); + $filesystem->getAdapter()->setMetadata($path, ['contentType' => $file->getMimeType()]); } $filesystem->write($path, file_get_contents($file->getPathname()), true); } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doRemove(PropertyMapping $mapping, $dir, $name) { @@ -73,7 +73,7 @@ protected function doRemove(PropertyMapping $mapping, $dir, $name) } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relative = false) { @@ -87,7 +87,7 @@ protected function doResolvePath(PropertyMapping $mapping, $dir, $name, $relativ } /** - * Get filesystem adapter from the property mapping + * Get filesystem adapter from the property mapping. * * @param PropertyMapping $mapping * diff --git a/Storage/StorageInterface.php b/Storage/StorageInterface.php index 86a15d39..67643ec5 100644 --- a/Storage/StorageInterface.php +++ b/Storage/StorageInterface.php @@ -15,16 +15,16 @@ interface StorageInterface * Uploads the file in the uploadable field of the specified object * according to the property configuration. * - * @param object $obj The object. - * @param PropertyMapping $mapping The mapping representing the field to upload. + * @param object $obj The object + * @param PropertyMapping $mapping The mapping representing the field to upload */ public function upload($obj, PropertyMapping $mapping); /** * Removes the files associated with the given mapping. * - * @param object $obj The object. - * @param PropertyMapping $mapping The mapping representing the field to remove. + * @param object $obj The object + * @param PropertyMapping $mapping The mapping representing the field to remove */ public function remove($obj, PropertyMapping $mapping); @@ -32,23 +32,23 @@ public function remove($obj, PropertyMapping $mapping); * Resolves the path for a file based on the specified object * and mapping name. * - * @param object $obj The object. - * @param string $fieldName The field to use. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. - * @param bool $relative Whether the path should be relative or absolute. + * @param object $obj The object + * @param string $fieldName The field to use + * @param string $className The object's class. Mandatory if $obj can't be used to determine it + * @param bool $relative Whether the path should be relative or absolute * - * @return string The path. + * @return string The path */ public function resolvePath($obj, $fieldName, $className = null, $relative = false); /** * Resolves the uri based on the specified object and mapping name. * - * @param object $obj The object. - * @param string $fieldName The field to use. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $fieldName The field to use + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return string The uri. + * @return string The uri */ public function resolveUri($obj, $fieldName, $className = null); @@ -56,11 +56,11 @@ public function resolveUri($obj, $fieldName, $className = null); * Returns a read-only stream based on the specified object and mapping * name. * - * @param object $obj The object. - * @param string $fieldName The field to use. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $fieldName The field to use + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return string The uri. + * @return string The uri */ public function resolveStream($obj, $fieldName, $className = null); } diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php index a2cf890a..480ca8ea 100644 --- a/Templating/Helper/UploaderHelper.php +++ b/Templating/Helper/UploaderHelper.php @@ -13,14 +13,14 @@ class UploaderHelper extends Helper { /** - * @var StorageInterface $storage + * @var StorageInterface */ protected $storage; /** * Constructs a new instance of UploaderHelper. * - * @param StorageInterface $storage The storage. + * @param StorageInterface $storage The storage */ public function __construct(StorageInterface $storage) { @@ -41,11 +41,11 @@ public function getName() * Gets the public path for the file associated with the * object. * - * @param object $obj The object. - * @param string $fieldName The field name. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $fieldName The field name + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return string The public asset path. + * @return string The public asset path */ public function asset($obj, $fieldName, $className = null) { diff --git a/Tests/Adapter/Propel/PropelORMAdapterTest.php b/Tests/Adapter/Propel/PropelORMAdapterTest.php index c1799029..8b6305a4 100644 --- a/Tests/Adapter/Propel/PropelORMAdapterTest.php +++ b/Tests/Adapter/Propel/PropelORMAdapterTest.php @@ -5,7 +5,7 @@ use Vich\UploaderBundle\Adapter\Propel\PropelORMAdapter; /** - * PropelORMAdapterTest + * PropelORMAdapterTest. * * @author Kévin Gomez */ diff --git a/Tests/DependencyInjection/VichUploaderExtensionTest.php b/Tests/DependencyInjection/VichUploaderExtensionTest.php index 18e2db97..2e1285c8 100644 --- a/Tests/DependencyInjection/VichUploaderExtensionTest.php +++ b/Tests/DependencyInjection/VichUploaderExtensionTest.php @@ -3,57 +3,56 @@ namespace Vich\UploaderBundle\Tests\DependencyInjection; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; - use Vich\UploaderBundle\DependencyInjection\VichUploaderExtension; class VichUploaderExtensionTest extends AbstractExtensionTestCase { protected function getContainerExtensions() { - return array( - new VichUploaderExtension() - ); + return [ + new VichUploaderExtension(), + ]; } protected function getMinimalConfiguration() { - return array( + return [ 'db_driver' => 'propel', - ); + ]; } public function setUp() { parent::setUp(); - $this->container->setParameter('kernel.bundles', array()); + $this->container->setParameter('kernel.bundles', []); $this->container->setParameter('kernel.cache_dir', sys_get_temp_dir()); } public function testStorageServiceParameterIsSet() { - $this->load(array( + $this->load([ 'storage' => 'gaufrette', - )); + ]); $this->assertContainerBuilderHasAlias('vich_uploader.storage', 'vich_uploader.storage.gaufrette'); } public function testStorageServiceCustom() { - $this->load(array( + $this->load([ 'storage' => '@acme.storage', - )); + ]); $this->assertContainerBuilderHasAlias('vich_uploader.storage', 'acme.storage'); } public function testExtraServiceFilesAreLoaded() { - $this->load(array( - 'twig' => true, - 'storage' =>'flysystem' - )); + $this->load([ + 'twig' => true, + 'storage' => 'flysystem', + ]); $this->assertContainerBuilderHasService('vich_uploader.storage.flysystem', 'Vich\UploaderBundle\Storage\FlysystemStorage'); $this->assertContainerBuilderHasService('vich_uploader.twig.extension.uploader', 'Vich\UploaderBundle\Twig\Extension\UploaderExtension'); @@ -61,19 +60,19 @@ public function testExtraServiceFilesAreLoaded() public function testMappingsServiceParameterIsSet() { - $this->load(array( - 'mappings' => $mappings = array( - 'foo' => array( - 'upload_destination' => 'web/', - 'uri_prefix' => '/', - 'namer' => array('service' => null, 'options' => null), - 'directory_namer' => array('service' => null, 'options' => null), - 'delete_on_remove' => true, - 'delete_on_update' => true, - 'inject_on_load' => true, - ) - ), - )); + $this->load([ + 'mappings' => $mappings = [ + 'foo' => [ + 'upload_destination' => 'web/', + 'uri_prefix' => '/', + 'namer' => ['service' => null, 'options' => null], + 'directory_namer' => ['service' => null, 'options' => null], + 'delete_on_remove' => true, + 'delete_on_update' => true, + 'inject_on_load' => true, + ], + ], + ]); // the default db_driver is copied into the mapping $mappings['foo']['db_driver'] = 'propel'; @@ -83,21 +82,21 @@ public function testMappingsServiceParameterIsSet() public function testDbDriverIsntOverriden() { - $this->load(array( + $this->load([ 'db_driver' => 'propel', - 'mappings' => $mappings = array( - 'foo' => array( - 'upload_destination' => 'web/', - 'uri_prefix' => '/', - 'namer' => array('service' => null, 'options' => null), - 'directory_namer' => array('service' => null, 'options' => null), - 'delete_on_remove' => true, - 'delete_on_update' => true, - 'inject_on_load' => true, - 'db_driver' => 'orm', - ) - ), - )); + 'mappings' => $mappings = [ + 'foo' => [ + 'upload_destination' => 'web/', + 'uri_prefix' => '/', + 'namer' => ['service' => null, 'options' => null], + 'directory_namer' => ['service' => null, 'options' => null], + 'delete_on_remove' => true, + 'delete_on_update' => true, + 'inject_on_load' => true, + 'db_driver' => 'orm', + ], + ], + ]); $this->assertContainerBuilderHasParameter('vich_uploader.mappings', $mappings); } diff --git a/Tests/DummyEntity.php b/Tests/DummyEntity.php index 21ec960d..e7839a25 100644 --- a/Tests/DummyEntity.php +++ b/Tests/DummyEntity.php @@ -6,8 +6,8 @@ /** * @Vich\Uploadable - * - * @author Dustin Dobervich + * + * @author Dustin Dobervich */ class DummyEntity { diff --git a/Tests/EventListener/Doctrine/CleanListenerTest.php b/Tests/EventListener/Doctrine/CleanListenerTest.php index 79309aa1..e4837240 100644 --- a/Tests/EventListener/Doctrine/CleanListenerTest.php +++ b/Tests/EventListener/Doctrine/CleanListenerTest.php @@ -12,7 +12,7 @@ class CleanListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -28,7 +28,7 @@ public function testGetSubscribedEvents() { $events = $this->listener->getSubscribedEvents(); - $this->assertSame(array('preUpdate'), $events); + $this->assertSame(['preUpdate'], $events); } /** @@ -46,9 +46,9 @@ public function testPreUpdate() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => 'field_name') - ))); + ->will($this->returnValue([ + ['propertyName' => 'field_name'], + ])); $this->handler ->expects($this->once()) diff --git a/Tests/EventListener/Doctrine/InjectListenerTest.php b/Tests/EventListener/Doctrine/InjectListenerTest.php index a5e4c0ef..613787c6 100644 --- a/Tests/EventListener/Doctrine/InjectListenerTest.php +++ b/Tests/EventListener/Doctrine/InjectListenerTest.php @@ -12,7 +12,7 @@ class InjectListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -28,7 +28,7 @@ public function testGetSubscribedEvents() { $events = $this->listener->getSubscribedEvents(); - $this->assertSame(array('postLoad'), $events); + $this->assertSame(['postLoad'], $events); } /** @@ -46,9 +46,9 @@ public function testPostLoad() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => 'field_name') - ))); + ->will($this->returnValue([ + ['propertyName' => 'field_name'], + ])); $this->handler ->expects($this->once()) diff --git a/Tests/EventListener/Doctrine/ListenerTestCase.php b/Tests/EventListener/Doctrine/ListenerTestCase.php index 951b551b..7a11d21b 100644 --- a/Tests/EventListener/Doctrine/ListenerTestCase.php +++ b/Tests/EventListener/Doctrine/ListenerTestCase.php @@ -18,17 +18,17 @@ class ListenerTestCase extends \PHPUnit_Framework_TestCase const MAPPING_NAME = 'dummy_mapping'; /** - * @var AdapterInterface $adapter + * @var AdapterInterface */ protected $adapter; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; /** - * @var UploadHandler $handler + * @var UploadHandler */ protected $handler; @@ -45,7 +45,7 @@ class ListenerTestCase extends \PHPUnit_Framework_TestCase protected $listener; /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -70,7 +70,7 @@ public function setUp() /** * Creates a mock adapter. * - * @return AdapterInterface The mock adapter. + * @return AdapterInterface The mock adapter */ protected function getAdapterMock() { @@ -80,7 +80,7 @@ protected function getAdapterMock() /** * Creates a mock metadata reader. * - * @return MetadataReader The mock metadata reader. + * @return MetadataReader The mock metadata reader */ protected function getMetadataReaderMock() { @@ -92,7 +92,7 @@ protected function getMetadataReaderMock() /** * Creates a mock handler. * - * @return UploadHandler The handler mock. + * @return UploadHandler The handler mock */ protected function getHandlerMock() { @@ -102,7 +102,7 @@ protected function getHandlerMock() } /** - * Creates a mock doctrine event + * Creates a mock doctrine event. * * @return EventArgs */ diff --git a/Tests/EventListener/Doctrine/RemoveListenerTest.php b/Tests/EventListener/Doctrine/RemoveListenerTest.php index f8e1b624..410fbf54 100644 --- a/Tests/EventListener/Doctrine/RemoveListenerTest.php +++ b/Tests/EventListener/Doctrine/RemoveListenerTest.php @@ -13,7 +13,7 @@ class RemoveListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -29,7 +29,7 @@ public function testGetSubscribedEvents() { $events = $this->listener->getSubscribedEvents(); - $this->assertSame(array('preRemove', 'postRemove'), $events); + $this->assertSame(['preRemove', 'postRemove'], $events); } public function testPreRemove() @@ -79,9 +79,9 @@ public function testPostRemove() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => 'field_name') - ))); + ->will($this->returnValue([ + ['propertyName' => 'field_name'], + ])); $this->handler ->expects($this->once()) diff --git a/Tests/EventListener/Doctrine/UploadListenerTest.php b/Tests/EventListener/Doctrine/UploadListenerTest.php index cf1f0bf0..7362a2d6 100644 --- a/Tests/EventListener/Doctrine/UploadListenerTest.php +++ b/Tests/EventListener/Doctrine/UploadListenerTest.php @@ -12,7 +12,7 @@ class UploadListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -28,7 +28,7 @@ public function testGetSubscribedEvents() { $events = $this->listener->getSubscribedEvents(); - $this->assertSame(array('prePersist', 'preUpdate'), $events); + $this->assertSame(['prePersist', 'preUpdate'], $events); } /** @@ -46,9 +46,9 @@ public function testPrePersist() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => 'field_name') - ))); + ->will($this->returnValue([ + ['propertyName' => 'field_name'], + ])); $this->handler ->expects($this->once()) @@ -96,9 +96,9 @@ public function testPreUpdate() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => 'field_name') - ))); + ->will($this->returnValue([ + ['propertyName' => 'field_name'], + ])); $this->handler ->expects($this->once()) diff --git a/Tests/EventListener/Propel/CleanListenerTest.php b/Tests/EventListener/Propel/CleanListenerTest.php index e96a2b4d..91a26a75 100644 --- a/Tests/EventListener/Propel/CleanListenerTest.php +++ b/Tests/EventListener/Propel/CleanListenerTest.php @@ -12,7 +12,7 @@ class CleanListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { diff --git a/Tests/EventListener/Propel/InjectListenerTest.php b/Tests/EventListener/Propel/InjectListenerTest.php index f669656d..96e68002 100644 --- a/Tests/EventListener/Propel/InjectListenerTest.php +++ b/Tests/EventListener/Propel/InjectListenerTest.php @@ -12,7 +12,7 @@ class InjectListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { diff --git a/Tests/EventListener/Propel/ListenerTestCase.php b/Tests/EventListener/Propel/ListenerTestCase.php index 99756432..4f1c34f9 100644 --- a/Tests/EventListener/Propel/ListenerTestCase.php +++ b/Tests/EventListener/Propel/ListenerTestCase.php @@ -19,22 +19,22 @@ class ListenerTestCase extends \PHPUnit_Framework_TestCase const MAPPING_NAME = 'mapping_name'; /** - * @var AdapterInterface $adapter + * @var AdapterInterface */ protected $adapter; /** - * @var UploadHandler $handler + * @var UploadHandler */ protected $handler; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; /** - * @var PropelUploaderListener $listener + * @var PropelUploaderListener */ protected $listener; @@ -49,7 +49,7 @@ class ListenerTestCase extends \PHPUnit_Framework_TestCase protected $object; /** - * Sets up the test + * Sets up the test. */ public function setUp() { @@ -70,15 +70,15 @@ public function setUp() ->expects($this->any()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) - ->will($this->returnValue(array( - array('propertyName' => self::FIELD_NAME) - ))); + ->will($this->returnValue([ + ['propertyName' => self::FIELD_NAME], + ])); } /** * Creates a mock adapter. * - * @return AdapterInterface The mock adapter. + * @return AdapterInterface The mock adapter */ protected function getAdapterMock() { @@ -88,7 +88,7 @@ protected function getAdapterMock() /** * Creates a mock handler. * - * @return UploadHandler The handler mock. + * @return UploadHandler The handler mock */ protected function getHandlerMock() { @@ -100,7 +100,7 @@ protected function getHandlerMock() /** * Creates a mock event. * - * @return GenericEvent The mock event. + * @return GenericEvent The mock event */ protected function getEventMock() { @@ -112,7 +112,7 @@ protected function getEventMock() /** * Creates a mock metadata reader. * - * @return MetadataReader The mock metadata reader. + * @return MetadataReader The mock metadata reader */ protected function getMetadataReaderMock() { diff --git a/Tests/EventListener/Propel/RemoveListenerTest.php b/Tests/EventListener/Propel/RemoveListenerTest.php index 52e6c8aa..a869e55a 100644 --- a/Tests/EventListener/Propel/RemoveListenerTest.php +++ b/Tests/EventListener/Propel/RemoveListenerTest.php @@ -12,7 +12,7 @@ class RemoveListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { diff --git a/Tests/EventListener/Propel/UploadListenerTest.php b/Tests/EventListener/Propel/UploadListenerTest.php index abfd41c6..e51126e2 100644 --- a/Tests/EventListener/Propel/UploadListenerTest.php +++ b/Tests/EventListener/Propel/UploadListenerTest.php @@ -12,7 +12,7 @@ class UploadListenerTest extends ListenerTestCase { /** - * Sets up the test + * Sets up the test. */ public function setUp() { diff --git a/Tests/Fixtures/App/app/AppKernel.php b/Tests/Fixtures/App/app/AppKernel.php index 9c336dd9..ea0b6919 100644 --- a/Tests/Fixtures/App/app/AppKernel.php +++ b/Tests/Fixtures/App/app/AppKernel.php @@ -7,14 +7,14 @@ class AppKernel extends Kernel { public function registerBundles() { - return array( + return [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Vich\UploaderBundle\VichUploaderBundle(), new Vich\TestBundle\VichTestBundle(), - ); + ]; } public function registerContainerConfiguration(LoaderInterface $loader) diff --git a/Tests/Fixtures/App/src/TestBundle/Controller/DefaultController.php b/Tests/Fixtures/App/src/TestBundle/Controller/DefaultController.php index c857e3ea..186a4992 100644 --- a/Tests/Fixtures/App/src/TestBundle/Controller/DefaultController.php +++ b/Tests/Fixtures/App/src/TestBundle/Controller/DefaultController.php @@ -44,7 +44,7 @@ public function submitAction(Request $request, $formType, $imageId = null) return $this->redirect($this->generateUrl('view', [ 'formType' => $formType, - 'imageId' => $image->getId() + 'imageId' => $image->getId(), ])); } diff --git a/Tests/Fixtures/App/src/TestBundle/Entity/Image.php b/Tests/Fixtures/App/src/TestBundle/Entity/Image.php index f8e702bb..eaee9c55 100644 --- a/Tests/Fixtures/App/src/TestBundle/Entity/Image.php +++ b/Tests/Fixtures/App/src/TestBundle/Entity/Image.php @@ -32,14 +32,14 @@ class Image /** * @Vich\UploadableField(mapping="image_mapping", fileNameProperty="imageName") * - * @var File $imageFile + * @var File */ protected $imageFile; /** * @ORM\Column(type="string", nullable=true) * - * @var string $imageName + * @var string */ protected $imageName; diff --git a/Tests/Functional/UploadTest.php b/Tests/Functional/UploadTest.php index 17a109cc..e4d0f4ea 100644 --- a/Tests/Functional/UploadTest.php +++ b/Tests/Functional/UploadTest.php @@ -15,31 +15,31 @@ public function testFileIsUploadedWithFileType() $form = $crawler->selectButton('form_save')->form(); $image = $this->getUploadedFile($client, 'symfony_black_03.png'); - $crawler = $client->submit($form, array( - 'form' => array( - 'title' => 'Test image', - 'imageFile' => array('file' => $image), - ), - )); + $crawler = $client->submit($form, [ + 'form' => [ + 'title' => 'Test image', + 'imageFile' => ['file' => $image], + ], + ]); // we should be redirected to the "view" page $this->assertTrue($client->getResponse()->isRedirect()); $crawler = $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful()); - $this->assertFileExists($this->getUploadsDir($client) . '/symfony_black_03.png', 'The file is uploaded'); + $this->assertFileExists($this->getUploadsDir($client).'/symfony_black_03.png', 'The file is uploaded'); // test the delete feature $this->assertCount(1, $crawler->filter('input[type=checkbox]'), 'the delete checkbox is here'); $form = $crawler->selectButton('form_save')->form(); - $crawler = $client->submit($form, array( - 'form' => array( - 'title' => 'Test image', - 'imageFile' => array('delete' => true), - ), - )); + $crawler = $client->submit($form, [ + 'form' => [ + 'title' => 'Test image', + 'imageFile' => ['delete' => true], + ], + ]); $this->assertTrue($client->getResponse()->isRedirect()); - $this->assertFileNotExists($this->getUploadsDir($client) . '/symfony_black_03.png', 'The file is deleted'); + $this->assertFileNotExists($this->getUploadsDir($client).'/symfony_black_03.png', 'The file is deleted'); } public function testFileIsUploadedWithImageType() @@ -53,30 +53,30 @@ public function testFileIsUploadedWithImageType() $form = $crawler->selectButton('form_save')->form(); $image = $this->getUploadedFile($client, 'symfony_black_03.png'); - $crawler = $client->submit($form, array( - 'form' => array( - 'title' => 'Test image', - 'imageFile' => array('file' => $image), - ), - )); + $crawler = $client->submit($form, [ + 'form' => [ + 'title' => 'Test image', + 'imageFile' => ['file' => $image], + ], + ]); // we should be redirected to the "view" page $this->assertTrue($client->getResponse()->isRedirect()); $crawler = $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful()); - $this->assertFileExists($this->getUploadsDir($client) . '/symfony_black_03.png', 'The file is uploaded'); + $this->assertFileExists($this->getUploadsDir($client).'/symfony_black_03.png', 'The file is uploaded'); // test the delete feature $this->assertCount(1, $crawler->filter('input[type=checkbox]'), 'the delete checkbox is here'); $form = $crawler->selectButton('form_save')->form(); - $crawler = $client->submit($form, array( - 'form' => array( - 'title' => 'Test image', - 'imageFile' => array('delete' => true), - ), - )); + $crawler = $client->submit($form, [ + 'form' => [ + 'title' => 'Test image', + 'imageFile' => ['delete' => true], + ], + ]); $this->assertTrue($client->getResponse()->isRedirect()); - $this->assertFileNotExists($this->getUploadsDir($client) . '/symfony_black_03.png', 'The file is deleted'); + $this->assertFileNotExists($this->getUploadsDir($client).'/symfony_black_03.png', 'The file is deleted'); } } diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 597eb523..a85550b9 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -4,7 +4,6 @@ use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\Tools\SchemaTool; - use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -13,7 +12,7 @@ class WebTestCase extends BaseWebTestCase protected function getUploadedFile($client, $name, $mimeType = 'image/png') { return new UploadedFile( - $this->getImagesDir($client) . DIRECTORY_SEPARATOR . $name, + $this->getImagesDir($client).DIRECTORY_SEPARATOR.$name, $name, $mimeType, 123 @@ -22,12 +21,12 @@ protected function getUploadedFile($client, $name, $mimeType = 'image/png') protected function getUploadsDir($client) { - return $client->getKernel()->getCacheDir() . '/images'; + return $client->getKernel()->getCacheDir().'/images'; } protected function getImagesDir($client) { - return $client->getKernel()->getRootDir() . '/Resources/images'; + return $client->getKernel()->getRootDir().'/Resources/images'; } protected function getContainer($client) diff --git a/Tests/Handler/UploadHandlerTest.php b/Tests/Handler/UploadHandlerTest.php index 8679b89c..941c9b54 100644 --- a/Tests/Handler/UploadHandlerTest.php +++ b/Tests/Handler/UploadHandlerTest.php @@ -42,7 +42,7 @@ public function setUp() public function testUpload() { - $this->expectEvents(array(Events::PRE_UPLOAD, Events::POST_UPLOAD)); + $this->expectEvents([Events::PRE_UPLOAD, Events::POST_UPLOAD]); $this->mapping ->expects($this->once()) @@ -72,17 +72,17 @@ public function testAnExceptionIsThrownIfMappingIsntFound($method) $this->factory = $this->getPropertyMappingFactoryMock(); $handler = new UploadHandler($this->factory, $this->storage, $this->injector, $this->dispatcher); - call_user_func(array($handler, $method), $this->object, self::FILE_FIELD); + call_user_func([$handler, $method], $this->object, self::FILE_FIELD); } public function methodProvider() { - return array( - array('upload'), - array('inject'), - array('remove'), - array('clean'), - ); + return [ + ['upload'], + ['inject'], + ['remove'], + ['clean'], + ]; } public function testUploadSkipsEmptyObjects() @@ -104,7 +104,7 @@ public function testUploadSkipsEmptyObjects() public function testInject() { - $this->expectEvents(array(Events::PRE_INJECT, Events::POST_INJECT)); + $this->expectEvents([Events::PRE_INJECT, Events::POST_INJECT]); $this->injector ->expects($this->once()) @@ -116,7 +116,7 @@ public function testInject() public function testClean() { - $this->expectEvents(array(Events::PRE_REMOVE, Events::POST_REMOVE)); + $this->expectEvents([Events::PRE_REMOVE, Events::POST_REMOVE]); $this->mapping ->expects($this->once()) @@ -159,7 +159,7 @@ public function testCleanSkipsEmptyObjects() public function testRemove() { - $this->expectEvents(array(Events::PRE_REMOVE, Events::POST_REMOVE)); + $this->expectEvents([Events::PRE_REMOVE, Events::POST_REMOVE]); $this->mapping ->expects($this->once()) diff --git a/Tests/Injector/FileInjectorTest.php b/Tests/Injector/FileInjectorTest.php index 27766d7e..7ec383e6 100644 --- a/Tests/Injector/FileInjectorTest.php +++ b/Tests/Injector/FileInjectorTest.php @@ -3,7 +3,6 @@ namespace Vich\UploaderBundle\Tests\Injector; use Symfony\Component\HttpFoundation\File\File; - use Vich\UploaderBundle\Injector\FileInjector; /** @@ -14,7 +13,7 @@ class FileInjectorTest extends \PHPUnit_Framework_TestCase { /** - * @var Vich\UploaderBundle\Storage\GaufretteStorage $storage + * @var Vich\UploaderBundle\Storage\GaufretteStorage */ protected $storage; diff --git a/Tests/Mapping/Annotation/UploadableFieldTest.php b/Tests/Mapping/Annotation/UploadableFieldTest.php index 21eb8bf9..0ca61987 100644 --- a/Tests/Mapping/Annotation/UploadableFieldTest.php +++ b/Tests/Mapping/Annotation/UploadableFieldTest.php @@ -16,8 +16,8 @@ class UploadableFieldTest extends \PHPUnit_Framework_TestCase */ public function testExceptionThrownWhenNoMappingAttribute() { - new UploadableField(array( - 'fileNameProperty' => 'fileName' - )); + new UploadableField([ + 'fileNameProperty' => 'fileName', + ]); } } diff --git a/Tests/Mapping/PropertyMappingFactoryTest.php b/Tests/Mapping/PropertyMappingFactoryTest.php index 0482bc4e..680c1d5a 100644 --- a/Tests/Mapping/PropertyMappingFactoryTest.php +++ b/Tests/Mapping/PropertyMappingFactoryTest.php @@ -15,12 +15,12 @@ class PropertyMappingFactoryTest extends \PHPUnit_Framework_TestCase { /** - * @var ContainerInterface $container + * @var ContainerInterface */ protected $container; /** - * @var MetadataReader $metadata + * @var MetadataReader */ protected $metadata; @@ -46,7 +46,7 @@ public function testFromObjectThrowsExceptionIfNotUploadable() ->method('isUploadable') ->will($this->returnValue(false)); - $factory = new PropertyMappingFactory($this->container, $this->metadata, array()); + $factory = new PropertyMappingFactory($this->container, $this->metadata, []); $factory->fromObject(new DummyEntity()); } @@ -58,13 +58,13 @@ public function testFromObjectThrowsExceptionIfNotUploadable() */ public function testFromObjectOneField($object, $givenClassName, $expectedClassName) { - $mappings = array( - 'dummy_file' => array( + $mappings = [ + 'dummy_file' => [ 'upload_destination' => 'images', - 'namer' => null, - 'directory_namer' => null - ) - ); + 'namer' => null, + 'directory_namer' => null, + ], + ]; $this->metadata ->expects($this->once()) @@ -76,13 +76,13 @@ public function testFromObjectOneField($object, $givenClassName, $expectedClassN ->expects($this->once()) ->method('getUploadableFields') ->with($expectedClassName) - ->will($this->returnValue(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) - ))); + ->will($this->returnValue([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); $mappings = $factory->fromObject($object, $givenClassName); @@ -102,34 +102,34 @@ public function fromObjectProvider() $obj = new DummyEntity(); $proxy = $this->createMock('Doctrine\Common\Persistence\Proxy'); - return array( - array( $obj, null, 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( $obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( $proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( array(), 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - ); + return [ + [$obj, null, 'Vich\UploaderBundle\Tests\DummyEntity'], + [$obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [$proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [[], 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + ]; } /** - * @expectedException RuntimeException + * @expectedException \RuntimeException */ public function testMappingCreationFailsIfTheClassNameCannotBeDetermined() { - $factory = new PropertyMappingFactory($this->container, $this->metadata, array()); - $factory->fromObject(array()); + $factory = new PropertyMappingFactory($this->container, $this->metadata, []); + $factory->fromObject([]); } public function testFromObjectOneFieldWithNoExplicitFilenameProperty() { $obj = new DummyEntity(); - $mappings = array( - 'dummy_file' => array( + $mappings = [ + 'dummy_file' => [ 'upload_destination' => 'images', - 'namer' => null, - 'directory_namer' => null - ) - ); + 'namer' => null, + 'directory_namer' => null, + ], + ]; $this->metadata ->expects($this->once()) @@ -141,12 +141,12 @@ public function testFromObjectOneFieldWithNoExplicitFilenameProperty() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity') - ->will($this->returnValue(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - ) - ))); + ->will($this->returnValue([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + ], + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); $mappings = $factory->fromObject($obj); @@ -164,18 +164,18 @@ public function testFromObjectOneFieldWithNoExplicitFilenameProperty() public function testFromObjectWithExplicitMapping() { - $mappings = array( - 'dummy_mapping' => array( + $mappings = [ + 'dummy_mapping' => [ 'upload_destination' => 'images', - 'namer' => null, - 'directory_namer' => null - ), - 'other_mapping' => array( + 'namer' => null, + 'directory_namer' => null, + ], + 'other_mapping' => [ 'upload_destination' => 'documents', - 'namer' => null, - 'directory_namer' => null - ) - ); + 'namer' => null, + 'directory_namer' => null, + ], + ]; $this->metadata ->expects($this->once()) @@ -187,20 +187,20 @@ public function testFromObjectWithExplicitMapping() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity') - ->will($this->returnValue(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - ), - 'other_file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'other_file', - ), - 'document' => array( - 'mapping' => 'other_mapping', - 'propertyName' => 'document', - ), - ))); + ->will($this->returnValue([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + ], + 'other_file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'other_file', + ], + 'document' => [ + 'mapping' => 'other_mapping', + 'propertyName' => 'document', + ], + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); $mappings = $factory->fromObject(new DummyEntity(), null, 'other_mapping'); @@ -220,9 +220,9 @@ public function testFromObjectWithExplicitMapping() */ public function testThrowsExceptionOnInvalidMappingName() { - $mappings = array( - 'bad_name' => array() - ); + $mappings = [ + 'bad_name' => [], + ]; $this->metadata ->expects($this->once()) @@ -234,13 +234,13 @@ public function testThrowsExceptionOnInvalidMappingName() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity') - ->will($this->returnValue(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) - ))); + ->will($this->returnValue([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); $factory->fromObject(new DummyEntity()); @@ -251,13 +251,13 @@ public function testThrowsExceptionOnInvalidMappingName() */ public function testFromField($object, $className, $expectedClassName) { - $mappings = array( - 'dummy_file' => array( + $mappings = [ + 'dummy_file' => [ 'upload_destination' => 'images', - 'namer' => null, - 'directory_namer' => null - ) - ); + 'namer' => null, + 'directory_namer' => null, + ], + ]; $this->metadata ->expects($this->once()) @@ -269,11 +269,11 @@ public function testFromField($object, $className, $expectedClassName) ->expects($this->once()) ->method('getUploadableField') ->with($expectedClassName, 'file') - ->will($this->returnValue(array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) + ->will($this->returnValue([ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ] )); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); @@ -287,12 +287,12 @@ public function fromFieldProvider() $obj = new DummyEntity(); $proxy = $this->createMock('Doctrine\Common\Persistence\Proxy'); - return array( - array( $obj, null, 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( $obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( $proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - array( array(), 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity' ), - ); + return [ + [$obj, null, 'Vich\UploaderBundle\Tests\DummyEntity'], + [$obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [$proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [[], 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + ]; } /** @@ -313,7 +313,7 @@ public function testFromFieldReturnsNullOnInvalidFieldName() ->with('Vich\UploaderBundle\Tests\DummyEntity') ->will($this->returnValue(null)); - $factory = new PropertyMappingFactory($this->container, $this->metadata, array()); + $factory = new PropertyMappingFactory($this->container, $this->metadata, []); $mapping = $factory->fromField(new DummyEntity(), 'oops'); $this->assertNull($mapping); @@ -321,12 +321,12 @@ public function testFromFieldReturnsNullOnInvalidFieldName() public function testCustomFileNameProperty() { - $mappings = array( - 'dummy_file' => array( + $mappings = [ + 'dummy_file' => [ 'namer' => false, - 'directory_namer' => false - ) - ); + 'directory_namer' => false, + ], + ]; $this->metadata ->expects($this->once()) @@ -338,10 +338,10 @@ public function testCustomFileNameProperty() ->expects($this->once()) ->method('getUploadableField') ->with('Vich\UploaderBundle\Tests\DummyEntity') - ->will($this->returnValue(array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file' - ))); + ->will($this->returnValue([ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings, '_suffix'); $mapping = $factory->fromField(new DummyEntity(), 'file'); @@ -351,23 +351,23 @@ public function testCustomFileNameProperty() public function testConfiguredNamersAreRetrievedFromContainer() { - $mappings = array( - 'dummy_file' => array( + $mappings = [ + 'dummy_file' => [ 'upload_destination' => 'images', - 'namer' => array('service' => 'my.custom.namer'), - 'directory_namer' => array('service' => 'my.custom.directory_namer'), - ) - ); + 'namer' => ['service' => 'my.custom.namer'], + 'directory_namer' => ['service' => 'my.custom.directory_namer'], + ], + ]; $namer = $this->createMock('Vich\UploaderBundle\Naming\NamerInterface'); $directoryNamer = $this->createMock('Vich\UploaderBundle\Naming\DirectoryNamerInterface'); $this->container ->method('get') - ->will($this->returnValueMap(array( - array('my.custom.namer', /* invalid behavior */ 1, $namer), - array('my.custom.directory_namer', /* invalid behavior */ 1, $directoryNamer), - ))); + ->will($this->returnValueMap([ + ['my.custom.namer', /* invalid behavior */ 1, $namer], + ['my.custom.directory_namer', /* invalid behavior */ 1, $directoryNamer], + ])); $this->metadata ->expects($this->once()) @@ -379,13 +379,13 @@ public function testConfiguredNamersAreRetrievedFromContainer() ->expects($this->once()) ->method('getUploadableFields') ->with('Vich\UploaderBundle\Tests\DummyEntity') - ->will($this->returnValue(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) - ))); + ->will($this->returnValue([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + ])); $factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings); $mappings = $factory->fromObject(new DummyEntity()); @@ -403,7 +403,7 @@ public function testConfiguredNamersAreRetrievedFromContainer() /** * Creates a mock container. * - * @return \Symfony\Component\DependencyInjection\ContainerInterface The container. + * @return \Symfony\Component\DependencyInjection\ContainerInterface The container */ protected function getContainerMock() { @@ -413,7 +413,7 @@ protected function getContainerMock() /** * Creates a mock metadata reader. * - * @return MetadataReader The metadata reader. + * @return MetadataReader The metadata reader */ protected function getMetadataReaderMock() { diff --git a/Tests/Mapping/PropertyMappingTest.php b/Tests/Mapping/PropertyMappingTest.php index d98915c0..c70838af 100644 --- a/Tests/Mapping/PropertyMappingTest.php +++ b/Tests/Mapping/PropertyMappingTest.php @@ -20,9 +20,9 @@ public function testConfiguredMappingAccess() { $object = new DummyEntity(); $prop = new PropertyMapping('file', 'fileName'); - $prop->setMapping(array( - 'upload_destination' => '/tmp', - )); + $prop->setMapping([ + 'upload_destination' => '/tmp', + ]); $this->assertEquals('', $prop->getUploadDir($object)); $this->assertEquals('/tmp', $prop->getUploadDestination()); @@ -48,15 +48,15 @@ public function propertiesAccessProvider() $object->setFileName('joe.png'); $object->setFile($date); - $array = array( - 'fileName' => 'joe.png', - 'file' => $date, - ); + $array = [ + 'fileName' => 'joe.png', + 'file' => $date, + ]; - return array( - array( $object, $date, 'joe.png' ), - array( $array, $date, 'joe.png' ), - ); + return [ + [$object, $date, 'joe.png'], + [$array, $date, 'joe.png'], + ]; } public function testPropertiesAreSet() @@ -79,9 +79,9 @@ public function testDirectoryNamerIsCalled($dir, $expectedDir) { $object = new DummyEntity(); $prop = new PropertyMapping('file', 'fileName'); - $prop->setMapping(array( + $prop->setMapping([ 'upload_destination' => '/tmp', - )); + ]); $namer = $this->createMock('Vich\UploaderBundle\Naming\DirectoryNamerInterface'); $namer @@ -98,12 +98,12 @@ public function testDirectoryNamerIsCalled($dir, $expectedDir) public function directoryProvider() { - return array( - array( 'other_dir', 'other_dir' ), - array( 'other_dir/', 'other_dir' ), - array( 'other_dir\\', 'other_dir' ), - array( 'other_dir\\sub_dir', 'other_dir\\sub_dir' ), - array( 'other_dir\\sub_dir\\', 'other_dir\\sub_dir' ), - ); + return [ + ['other_dir', 'other_dir'], + ['other_dir/', 'other_dir'], + ['other_dir\\', 'other_dir'], + ['other_dir\\sub_dir', 'other_dir\\sub_dir'], + ['other_dir\\sub_dir\\', 'other_dir\\sub_dir'], + ]; } } diff --git a/Tests/Metadata/ClassMetadataTest.php b/Tests/Metadata/ClassMetadataTest.php index c8499710..94dfbb7a 100644 --- a/Tests/Metadata/ClassMetadataTest.php +++ b/Tests/Metadata/ClassMetadataTest.php @@ -8,7 +8,7 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase { public function testFieldsAreSerialized() { - $fields = array('foo', 'bar', 'baz'); + $fields = ['foo', 'bar', 'baz']; $metadata = new ClassMetadata('DateTime'); $metadata->fields = $fields; diff --git a/Tests/Metadata/Driver/AnnotationDriverTest.php b/Tests/Metadata/Driver/AnnotationDriverTest.php index 2ec1f495..d9494ea2 100644 --- a/Tests/Metadata/Driver/AnnotationDriverTest.php +++ b/Tests/Metadata/Driver/AnnotationDriverTest.php @@ -8,7 +8,7 @@ use Vich\UploaderBundle\Tests\TwoFieldsDummyEntity; /** - * AnnotationDriverTest + * AnnotationDriverTest. * * @author Kévin Gomez */ @@ -26,23 +26,23 @@ public function testReadUploadableAnnotation() $reader ->expects($this->at(1)) ->method('getPropertyAnnotation') - ->will($this->returnValue(new UploadableField(array( - 'mapping' => 'dummy_file', - 'fileNameProperty' => 'fileName' - )))); + ->will($this->returnValue(new UploadableField([ + 'mapping' => 'dummy_file', + 'fileNameProperty' => 'fileName', + ]))); $driver = new AnnotationDriver($reader); $metadata = $driver->loadMetadataForClass(new \ReflectionClass($entity)); $this->assertInstanceOf('\Vich\UploaderBundle\Metadata\ClassMetadata', $metadata); $this->assertObjectHasAttribute('fields', $metadata); - $this->assertEquals(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) - ), $metadata->fields); + $this->assertEquals([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + ], $metadata->fields); } public function testReadUploadableAnnotationReturnsNullWhenNonePresent() @@ -76,33 +76,33 @@ public function testReadTwoUploadableFields() $reader ->expects($this->at(1)) ->method('getPropertyAnnotation') - ->will($this->returnValue(new UploadableField(array( - 'mapping' => 'dummy_file', - 'fileNameProperty' => 'fileName' - )))); + ->will($this->returnValue(new UploadableField([ + 'mapping' => 'dummy_file', + 'fileNameProperty' => 'fileName', + ]))); $reader ->expects($this->at(3)) ->method('getPropertyAnnotation') - ->will($this->returnValue(new UploadableField(array( - 'mapping' => 'dummy_image', - 'fileNameProperty' => 'imageName' - )))); + ->will($this->returnValue(new UploadableField([ + 'mapping' => 'dummy_image', + 'fileNameProperty' => 'imageName', + ]))); $driver = new AnnotationDriver($reader); $metadata = $driver->loadMetadataForClass(new \ReflectionClass($entity)); - $this->assertEquals(array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ), - 'image' => array( - 'mapping' => 'dummy_image', - 'propertyName' => 'image', - 'fileNameProperty' => 'imageName', - ) - ), $metadata->fields); + $this->assertEquals([ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + 'image' => [ + 'mapping' => 'dummy_image', + 'propertyName' => 'image', + 'fileNameProperty' => 'imageName', + ], + ], $metadata->fields); } public function testReadNoUploadableFieldsWhenNoneExist() diff --git a/Tests/Metadata/Driver/FileLocatorTest.php b/Tests/Metadata/Driver/FileLocatorTest.php index 0efaad3c..eac03204 100644 --- a/Tests/Metadata/Driver/FileLocatorTest.php +++ b/Tests/Metadata/Driver/FileLocatorTest.php @@ -4,11 +4,10 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; - use Vich\UploaderBundle\Metadata\Driver\FileLocator; /** - * FileLocatorTest + * FileLocatorTest. * * @author Kévin Gomez */ @@ -30,18 +29,18 @@ class FileLocatorTest extends \PHPUnit_Framework_TestCase public function setUp() { // initialize the virtual filesystem - $this->root = vfsStream::setup('vich_uploader_bundle', null, array( - 'vich_uploader' => array( - 'Foo.yml' => 'some content', - 'FooBaz.yml' => 'some content', - 'Bar.yml' => 'some content', - 'Baz.xml' => 'some content', - ), - )); + $this->root = vfsStream::setup('vich_uploader_bundle', null, [ + 'vich_uploader' => [ + 'Foo.yml' => 'some content', + 'FooBaz.yml' => 'some content', + 'Bar.yml' => 'some content', + 'Baz.xml' => 'some content', + ], + ]); - $this->locator = new FileLocator(array( - '\DummyNamespace' => $this->root->url() . DIRECTORY_SEPARATOR . 'vich_uploader', - )); + $this->locator = new FileLocator([ + '\DummyNamespace' => $this->root->url().DIRECTORY_SEPARATOR.'vich_uploader', + ]); } /** @@ -68,12 +67,12 @@ public function testFindFileForClass($namespace, $name, $extension, $path) public function fileProvider() { - return array( - array( '\DummyNamespace', 'Foo', 'yml', 'vfs://vich_uploader_bundle/vich_uploader/Foo.yml' ), - array( '\DummyNamespace', 'FooBaz', 'yml', 'vfs://vich_uploader_bundle/vich_uploader/FooBaz.yml' ), - array( '\DummyNamespace', 'Baz', 'xml', 'vfs://vich_uploader_bundle/vich_uploader/Baz.xml' ), - array( '\DummyNamespace', 'Dummy', 'xml', null ), - ); + return [ + ['\DummyNamespace', 'Foo', 'yml', 'vfs://vich_uploader_bundle/vich_uploader/Foo.yml'], + ['\DummyNamespace', 'FooBaz', 'yml', 'vfs://vich_uploader_bundle/vich_uploader/FooBaz.yml'], + ['\DummyNamespace', 'Baz', 'xml', 'vfs://vich_uploader_bundle/vich_uploader/Baz.xml'], + ['\DummyNamespace', 'Dummy', 'xml', null], + ]; } /** @@ -91,10 +90,10 @@ public function testFindAllClasses($extension, array $expectedClasses) public function classesProvider() { - return array( - array( 'yml', array('Foo.yml', 'FooBaz.yml', 'Bar.yml') ), - array( 'xml', array('Baz.xml') ), - array( 'php', array() ), - ); + return [ + ['yml', ['Foo.yml', 'FooBaz.yml', 'Bar.yml']], + ['xml', ['Baz.xml']], + ['php', []], + ]; } } diff --git a/Tests/Metadata/Driver/YamlDriverTest.php b/Tests/Metadata/Driver/YamlDriverTest.php index 9abef3f3..8513916a 100644 --- a/Tests/Metadata/Driver/YamlDriverTest.php +++ b/Tests/Metadata/Driver/YamlDriverTest.php @@ -5,21 +5,21 @@ use Vich\UploaderBundle\Metadata\Driver\YamlDriver; /** - * YamlDriverTest + * YamlDriverTest. * * @author Kévin Gomez */ class YamlDriverTest extends \PHPUnit_Framework_TestCase { /** - * @expectedException RuntimeException + * @expectedException \RuntimeException */ public function testInconsistentYamlFile() { $rClass = new \ReflectionClass('\DateTime'); $driver = $this->getDriver($rClass); - $driver->mappingContent = array(); + $driver->mappingContent = []; $driver->loadMetadataForClass($rClass); } @@ -32,9 +32,9 @@ public function testLoadMetadataForClass($mapping, $expectedMetadata) $rClass = new \ReflectionClass('\DateTime'); $driver = $this->getDriver($rClass); - $driver->mappingContent = array( - $rClass->name => $mapping - ); + $driver->mappingContent = [ + $rClass->name => $mapping, + ]; $metadata = $driver->loadMetadataForClass($rClass); @@ -59,52 +59,52 @@ protected function getDriver(\ReflectionClass $class, $found = true) public function fieldsProvider() { - $singleField = array( - 'mapping' => array( - 'file' => array( - 'mapping' => 'dummy_file', + $singleField = [ + 'mapping' => [ + 'file' => [ + 'mapping' => 'dummy_file', 'filename_property' => 'fileName', - ) - ), - 'metadata' => array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ) - ) - ); - - $severalFields = array( - 'mapping' => array( - 'file' => array( + ], + ], + 'metadata' => [ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + ], + ]; + + $severalFields = [ + 'mapping' => [ + 'file' => [ 'mapping' => 'dummy_file', 'filename_property' => 'fileName', - ), - 'image' => array( + ], + 'image' => [ 'mapping' => 'dummy_image', 'filename_property' => 'imageName', - ) - ), - 'metadata' => array( - 'file' => array( - 'mapping' => 'dummy_file', - 'propertyName' => 'file', - 'fileNameProperty' => 'fileName', - ), - 'image' => array( - 'mapping' => 'dummy_image', - 'propertyName' => 'image', - 'fileNameProperty' => 'imageName', - ) - ) - ); - - return array( - array( array(), array() ), - array( $singleField['mapping'], $singleField['metadata'] ), - array( $severalFields['mapping'], $severalFields['metadata'] ), - ); + ], + ], + 'metadata' => [ + 'file' => [ + 'mapping' => 'dummy_file', + 'propertyName' => 'file', + 'fileNameProperty' => 'fileName', + ], + 'image' => [ + 'mapping' => 'dummy_image', + 'propertyName' => 'image', + 'fileNameProperty' => 'imageName', + ], + ], + ]; + + return [ + [[], []], + [$singleField['mapping'], $singleField['metadata']], + [$severalFields['mapping'], $severalFields['metadata']], + ]; } } diff --git a/Tests/Metadata/MetadataReaderTest.php b/Tests/Metadata/MetadataReaderTest.php index 7942fcf8..f473e9b5 100644 --- a/Tests/Metadata/MetadataReaderTest.php +++ b/Tests/Metadata/MetadataReaderTest.php @@ -28,11 +28,11 @@ public function testIsUploadable() public function testIsUploadableWithGivenMapping() { - $fields = array('field' => array('mapping' => 'joe')); - $classMetadata = new \stdClass; + $fields = ['field' => ['mapping' => 'joe']]; + $classMetadata = new \stdClass(); $classMetadata->fields = $fields; - $metadata = new \stdClass; - $metadata->classMetadata = array('ClassName' => $classMetadata); + $metadata = new \stdClass(); + $metadata->classMetadata = ['ClassName' => $classMetadata]; $this->factory ->method('getMetadataForClass') @@ -65,11 +65,11 @@ public function testGetUploadableClassesForwardsCallsToTheFactory() public function testGetUploadableFields() { - $fields = array('foo', 'bar', 'baz'); - $classMetadata = new \stdClass; + $fields = ['foo', 'bar', 'baz']; + $classMetadata = new \stdClass(); $classMetadata->fields = $fields; - $metadata = new \stdClass; - $metadata->classMetadata = array('ClassName' => $classMetadata); + $metadata = new \stdClass(); + $metadata->classMetadata = ['ClassName' => $classMetadata]; $this->factory ->expects($this->once()) @@ -82,15 +82,15 @@ public function testGetUploadableFields() public function testGetUploadableFieldsWithInheritance() { - $classMetadata = new \stdClass; - $classMetadata->fields = array('bar', 'baz'); - $subClassMetadata = new \stdClass; - $subClassMetadata->fields = array('foo'); - $metadata = new \stdClass; - $metadata->classMetadata = array( - 'ClassName' => $classMetadata, - 'SubClassName' => $subClassMetadata - ); + $classMetadata = new \stdClass(); + $classMetadata->fields = ['bar', 'baz']; + $subClassMetadata = new \stdClass(); + $subClassMetadata->fields = ['foo']; + $metadata = new \stdClass(); + $metadata->classMetadata = [ + 'ClassName' => $classMetadata, + 'SubClassName' => $subClassMetadata, + ]; $this->factory ->expects($this->once()) @@ -98,7 +98,7 @@ public function testGetUploadableFieldsWithInheritance() ->with('SubClassName') ->will($this->returnValue($metadata)); - $this->assertSame(array('bar', 'baz', 'foo'), $this->reader->getUploadableFields('SubClassName')); + $this->assertSame(['bar', 'baz', 'foo'], $this->reader->getUploadableFields('SubClassName')); } /** @@ -106,10 +106,10 @@ public function testGetUploadableFieldsWithInheritance() */ public function testGetUploadableField(array $fields, $expectedMetadata) { - $classMetadata = new \stdClass; + $classMetadata = new \stdClass(); $classMetadata->fields = $fields; - $metadata = new \stdClass; - $metadata->classMetadata = array('ClassName' => $classMetadata); + $metadata = new \stdClass(); + $metadata->classMetadata = ['ClassName' => $classMetadata]; $this->factory ->expects($this->once()) @@ -122,9 +122,9 @@ public function testGetUploadableField(array $fields, $expectedMetadata) public function fieldsMetadataProvider() { - return array( - array( array('field' => 'toto'), 'toto' ), - array( array('lala' => 'toto'), null ), - ); + return [ + [['field' => 'toto'], 'toto'], + [['lala' => 'toto'], null], + ]; } } diff --git a/Tests/Naming/HashNamerTest.php b/Tests/Naming/HashNamerTest.php index 233ad443..77f1d4cd 100644 --- a/Tests/Naming/HashNamerTest.php +++ b/Tests/Naming/HashNamerTest.php @@ -21,12 +21,12 @@ class HashNamerTest extends TestCase { public function fileDataProvider() { - return array( - array('81fe8bfe87576c3ecb22426f8e57847382917acf.jpg', 'jpg', 'sha1', null), - array('81fe8bfe87576c3ecb22426f8e57847382917acf', '', 'sha1', null), - array('e2fc714c4727ee9395f324cd2e7f331f.jpg', 'jpg', 'md5', null), - array('81fe8bfe87576c3ecb22.jpg', 'jpg', 'sha1', 20), - ); + return [ + ['81fe8bfe87576c3ecb22426f8e57847382917acf.jpg', 'jpg', 'sha1', null], + ['81fe8bfe87576c3ecb22426f8e57847382917acf', '', 'sha1', null], + ['e2fc714c4727ee9395f324cd2e7f331f.jpg', 'jpg', 'md5', null], + ['81fe8bfe87576c3ecb22.jpg', 'jpg', 'sha1', 20], + ]; } /** @@ -49,7 +49,7 @@ public function testNameReturnsTheRightName($expectedFileName, $extension, $algo ->will($this->returnValue($file)); $namer = new HashNamer(); - $namer->configure(array('algorithm' => $algorithm, 'length' => $length)); + $namer->configure(['algorithm' => $algorithm, 'length' => $length]); $this->assertSame($expectedFileName, $namer->name($entity, $mapping)); } diff --git a/Tests/Naming/OrignameNamerTest.php b/Tests/Naming/OrignameNamerTest.php index b02bff7a..eecffa9c 100644 --- a/Tests/Naming/OrignameNamerTest.php +++ b/Tests/Naming/OrignameNamerTest.php @@ -14,11 +14,11 @@ class OrignameNamerTest extends TestCase { public function fileDataProvider() { - return array( - array('file.jpeg', '/[a-z0-9]{13}_file.jpeg/', false), - array('file', '/[a-z0-9]{13}_file/', false), - array('Yéöù.jpeg', '/[a-z0-9]{13}_Yeou.jpeg/', true), - ); + return [ + ['file.jpeg', '/[a-z0-9]{13}_file.jpeg/', false], + ['file', '/[a-z0-9]{13}_file/', false], + ['Yéöù.jpeg', '/[a-z0-9]{13}_Yeou.jpeg/', true], + ]; } /** @@ -43,7 +43,7 @@ public function testNameReturnsAnUniqueName($name, $pattern, $transliterate) ->will($this->returnValue($file)); $namer = new OrignameNamer(); - $namer->configure(array('transliterate' => $transliterate)); + $namer->configure(['transliterate' => $transliterate]); $this->assertRegExp($pattern, $namer->name($entity, $mapping)); } diff --git a/Tests/Naming/PropertyNamerTest.php b/Tests/Naming/PropertyNamerTest.php index 9e29cd3b..57ab35a4 100644 --- a/Tests/Naming/PropertyNamerTest.php +++ b/Tests/Naming/PropertyNamerTest.php @@ -21,12 +21,12 @@ public function fileDataProvider() $weird_entity = new DummyEntity(); $weird_entity->someProperty = 'Yéô'; - return array( - array('some-file-name.jpeg', 'foo.jpeg', $entity, 'someProperty', false), - array('some-file-name', 'foo', $entity, 'someProperty', false), - array('some-file-name.jpeg', 'generated-file-name.jpeg', $entity, 'generateFileName', false), // method call - array('some-file-name.jpeg', 'Yeo.jpeg', $weird_entity, 'someProperty', true), // transliteration enabled - ); + return [ + ['some-file-name.jpeg', 'foo.jpeg', $entity, 'someProperty', false], + ['some-file-name', 'foo', $entity, 'someProperty', false], + ['some-file-name.jpeg', 'generated-file-name.jpeg', $entity, 'generateFileName', false], // method call + ['some-file-name.jpeg', 'Yeo.jpeg', $weird_entity, 'someProperty', true], // transliteration enabled + ]; } /** @@ -47,7 +47,7 @@ public function testNameReturnsTheRightName($originalFileName, $expectedFileName ->will($this->returnValue($file)); $namer = new PropertyNamer(); - $namer->configure(array('property' => $propertyName, 'transliterate' => $transliterate)); + $namer->configure(['property' => $propertyName, 'transliterate' => $transliterate]); $this->assertSame($expectedFileName, $namer->name($entity, $mapping)); } @@ -57,11 +57,11 @@ public function testNameReturnsTheRightName($originalFileName, $expectedFileName */ public function testNameFailsIfThePropertyDoesNotExist() { - $entity = new DummyEntity(); + $entity = new DummyEntity(); $mapping = $this->getPropertyMappingMock(); $namer = new PropertyNamer(); - $namer->configure(array('property' => 'nonExistentProperty')); + $namer->configure(['property' => 'nonExistentProperty']); $namer->name($entity, $mapping); } @@ -72,9 +72,9 @@ public function testNameFailsIfThePropertyDoesNotExist() public function testNameFailsIfThePropertyIsEmpty() { $mapping = $this->getPropertyMappingMock(); - $namer = new PropertyNamer(); + $namer = new PropertyNamer(); - $namer->configure(array('property' => 'someProperty')); + $namer->configure(['property' => 'someProperty']); $namer->name(new DummyEntity(), $mapping); } @@ -86,7 +86,7 @@ public function testNameFailsIfThePropertyIsEmpty() public function testNamerNeedsToBeConfigured() { $mapping = $this->getPropertyMappingMock(); - $namer = new PropertyNamer(); + $namer = new PropertyNamer(); $namer->name(new DummyEntity(), $mapping); } @@ -99,6 +99,6 @@ public function testConfigurationFailsIfThePropertyIsntSpecified() { $namer = new PropertyNamer(); - $namer->configure(array('incorrect' => 'options')); + $namer->configure(['incorrect' => 'options']); } } diff --git a/Tests/Naming/SubdirDirectoryNamerTest.php b/Tests/Naming/SubdirDirectoryNamerTest.php index af8e376f..473dea9c 100644 --- a/Tests/Naming/SubdirDirectoryNamerTest.php +++ b/Tests/Naming/SubdirDirectoryNamerTest.php @@ -13,13 +13,13 @@ class SubdirDirectoryNamerTest extends TestCase { public function fileDataProvider() { - return array( - array('0123456789.jpg', '01', 2, 1), - array('0123456789.jpg', '01/23', 2, 2), - array('0123456789.jpg', '012', 3, 1), - array('0123456789.jpg', '0', 1, 1), - array('0123456789.jpg', '0/1/2/3', 1, 4), - ); + return [ + ['0123456789.jpg', '01', 2, 1], + ['0123456789.jpg', '01/23', 2, 2], + ['0123456789.jpg', '012', 3, 1], + ['0123456789.jpg', '0', 1, 1], + ['0123456789.jpg', '0/1/2/3', 1, 4], + ]; } /** @@ -37,9 +37,8 @@ public function testNameReturnsTheRightName($fileName, $expectedFileName, $chars ->will($this->returnValue($fileName)); $namer = new SubdirDirectoryNamer(); - $namer->configure(array('chars_per_dir' => $charsPerDir, 'dirs' => $dirs)); + $namer->configure(['chars_per_dir' => $charsPerDir, 'dirs' => $dirs]); $this->assertSame($expectedFileName, $namer->directoryName($entity, $mapping)); } } - diff --git a/Tests/Naming/UniqidNamerTest.php b/Tests/Naming/UniqidNamerTest.php index d5dc61d8..30a7e866 100644 --- a/Tests/Naming/UniqidNamerTest.php +++ b/Tests/Naming/UniqidNamerTest.php @@ -14,13 +14,13 @@ class UniqidNamerTest extends TestCase { public function fileDataProvider() { - return array( + return [ // original_name, guessed_extension, pattern - array('lala.jpeg', null, '/[a-z0-9]{13}.jpeg/'), - array('lala.mp3', 'mpga', '/[a-z0-9]{13}.mp3/'), - array('lala', 'mpga', '/[a-z0-9]{13}.mpga/'), - array('lala', null, '/[a-z0-9]{13}/'), - ); + ['lala.jpeg', null, '/[a-z0-9]{13}.jpeg/'], + ['lala.mp3', 'mpga', '/[a-z0-9]{13}.mp3/'], + ['lala', 'mpga', '/[a-z0-9]{13}.mpga/'], + ['lala', null, '/[a-z0-9]{13}/'], + ]; } /** diff --git a/Tests/Storage/FileSystemStorageTest.php b/Tests/Storage/FileSystemStorageTest.php index b07426ad..7c98abfe 100644 --- a/Tests/Storage/FileSystemStorageTest.php +++ b/Tests/Storage/FileSystemStorageTest.php @@ -12,7 +12,7 @@ class FileSystemStorageTest extends StorageTestCase { /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getStorage() { @@ -23,7 +23,7 @@ protected function getStorage() * Tests the upload method skips a mapping which has a non * uploadable property value. * - * @expectedException LogicException + * @expectedException \LogicException * @dataProvider invalidFileProvider * @group upload */ @@ -70,7 +70,7 @@ public function testRemoveSkipsEmptyFilenameProperties($propertyValue) } /** - * Test the remove method skips trying to remove a file that no longer exists + * Test the remove method skips trying to remove a file that no longer exists. */ public function testRemoveSkipsNonExistingFile() { @@ -100,7 +100,7 @@ public function testRemove() ->will($this->returnValue('test.txt')); $this->storage->remove($this->object, $this->mapping); - $this->assertFalse($this->root->hasChild('uploads' . DIRECTORY_SEPARATOR . 'test.txt')); + $this->assertFalse($this->root->hasChild('uploads'.DIRECTORY_SEPARATOR.'test.txt')); } /** @@ -177,7 +177,7 @@ public function testResolveUriReturnsNullIfNoFile() } /** - * Test the resolve uri + * Test the resolve uri. * * @dataProvider resolveUriDataProvider */ @@ -239,24 +239,24 @@ public function testResolveStream() public function resolveUriDataProvider() { - return array( - array( + return [ + [ '', - '/uploads/file.txt' - ), - array( + '/uploads/file.txt', + ], + [ 'dir', - '/uploads/dir/file.txt' - ), - array( + '/uploads/dir/file.txt', + ], + [ 'dir/sub-dir', - '/uploads/dir/sub-dir/file.txt' - ), - array( + '/uploads/dir/sub-dir/file.txt', + ], + [ 'dir\\sub-dir', - '/uploads/dir/sub-dir/file.txt' - ), - ); + '/uploads/dir/sub-dir/file.txt', + ], + ]; } /** @@ -299,23 +299,23 @@ public function testUploadedFileIsCorrectlyMoved($uploadDir, $dir, $expectedDir) public function filenameWithDirectoriesDataProvider() { - return array( + return [ // upload dir, dir, expected dir - array( + [ '/root_dir', '', '/root_dir/', - ), - array( + ], + [ '/root_dir', 'dir_1', '/root_dir/dir_1', - ), - array( + ], + [ '/root_dir', 'dir_1/dir_2', '/root_dir/dir_1/dir_2', - ), - ); + ], + ]; } } diff --git a/Tests/Storage/FlysystemStorageTest.php b/Tests/Storage/FlysystemStorageTest.php index 2e767d9b..a25ea76e 100644 --- a/Tests/Storage/FlysystemStorageTest.php +++ b/Tests/Storage/FlysystemStorageTest.php @@ -16,7 +16,7 @@ class FlysystemStorageTest extends StorageTestCase const FS_KEY = 'filesystemKey'; /** - * @var MountManager $mountManager + * @var MountManager */ protected $mountManager; @@ -32,9 +32,8 @@ public static function setUpBeforeClass() } } - /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getStorage() { @@ -70,7 +69,7 @@ public function testUpload() $file ->expects($this->once()) ->method('getRealPath') - ->will($this->returnValue($this->root->url() . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'test.txt')); + ->will($this->returnValue($this->root->url().DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'test.txt')); $file ->expects($this->once()) ->method('getClientOriginalName') @@ -162,19 +161,19 @@ public function testResolvePath($uploadDir, $expectedPath, $relative) public function pathProvider() { - return array( + return [ // dir, path, relative - array( null, 'file.txt', true ), - array( null, '/absolute/file.txt', false ), - array( 'foo', 'foo/file.txt', true ), - array( 'foo', '/absolute/foo/file.txt', false ), - ); + [null, 'file.txt', true], + [null, '/absolute/file.txt', false], + ['foo', 'foo/file.txt', true], + ['foo', '/absolute/foo/file.txt', false], + ]; } /** * Creates a filesystem map mock. * - * @return MountManager The mount manager. + * @return MountManager The mount manager */ protected function getMountManagerMock() { diff --git a/Tests/Storage/GaufretteStorageTest.php b/Tests/Storage/GaufretteStorageTest.php index 239b9071..0fe373b8 100644 --- a/Tests/Storage/GaufretteStorageTest.php +++ b/Tests/Storage/GaufretteStorageTest.php @@ -5,7 +5,6 @@ use Gaufrette\Filesystem; use Gaufrette\Exception\FileNotFound; use Knp\Bundle\GaufretteBundle\FilesystemMap; - use Vich\UploaderBundle\Storage\GaufretteStorage; /** @@ -16,12 +15,12 @@ class GaufretteStorageTest extends StorageTestCase { /** - * @var FilesystemMap $factory + * @var FilesystemMap */ protected $filesystemMap; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getStorage() { @@ -42,7 +41,7 @@ public function setUp() * Tests the upload method skips a mapping which has a non * uploadable property value. * - * @expectedException LogicException + * @expectedException \LogicException * @dataProvider invalidFileProvider * @group upload */ @@ -164,18 +163,18 @@ public function testResolveUriFileNull() public function pathProvider() { - return array( + return [ // protocol, fs identifier, upload dir, full path, relative - array( 'gaufrette', 'filesystemKey', null, 'gaufrette://filesystemKey/file.txt', false ), - array( 'data', 'filesystemKey', null, 'data://filesystemKey/file.txt', false ), - array( 'gaufrette', 'filesystemKey', 'foo', 'gaufrette://filesystemKey/foo/file.txt', false ), - array( 'gaufrette', 'filesystemKey', null, 'file.txt', true), - array( 'gaufrette', 'filesystemKey', 'foo', 'foo/file.txt', true ), - ); + ['gaufrette', 'filesystemKey', null, 'gaufrette://filesystemKey/file.txt', false], + ['data', 'filesystemKey', null, 'data://filesystemKey/file.txt', false], + ['gaufrette', 'filesystemKey', 'foo', 'gaufrette://filesystemKey/foo/file.txt', false], + ['gaufrette', 'filesystemKey', null, 'file.txt', true], + ['gaufrette', 'filesystemKey', 'foo', 'foo/file.txt', true], + ]; } /** - * Test the remove method does delete file from gaufrette filesystem + * Test the remove method does delete file from gaufrette filesystem. */ public function testThatRemoveMethodDoesDeleteFile() { @@ -205,7 +204,7 @@ public function testThatRemoveMethodDoesDeleteFile() } /** - * Test that FileNotFound exception is catched + * Test that FileNotFound exception is catched. */ public function testRemoveNotFoundFile() { @@ -249,7 +248,7 @@ public function testUploadSetsMetadataWhenUsingMetadataSupporterAdapter() $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->getValidUploadDir() . DIRECTORY_SEPARATOR . 'test.txt')); + ->will($this->returnValue($this->getValidUploadDir().DIRECTORY_SEPARATOR.'test.txt')); $this->mapping ->expects($this->once()) @@ -298,7 +297,7 @@ public function testUploadDoesNotSetMetadataWhenUsingNonMetadataSupporterAdapter $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->getValidUploadDir() . DIRECTORY_SEPARATOR . 'test.txt')); + ->will($this->returnValue($this->getValidUploadDir().DIRECTORY_SEPARATOR.'test.txt')); $this->mapping ->expects($this->once()) @@ -336,7 +335,7 @@ public function testUploadDoesNotSetMetadataWhenUsingNonMetadataSupporterAdapter /** * Creates a mock of gaufrette filesystem map. * - * @return FilesystemMap The filesystem map. + * @return FilesystemMap The filesystem map */ protected function getFilesystemMapMock() { @@ -349,7 +348,7 @@ protected function getFilesystemMapMock() /** * Creates a mock of gaufrette filesystem. * - * @return Filesystem The gaufrette filesystem object. + * @return Filesystem The gaufrette filesystem object */ protected function getFilesystemMock() { diff --git a/Tests/Storage/StorageTestCase.php b/Tests/Storage/StorageTestCase.php index 8c44973a..cb66cc4c 100644 --- a/Tests/Storage/StorageTestCase.php +++ b/Tests/Storage/StorageTestCase.php @@ -5,7 +5,6 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use Symfony\Component\HttpFoundation\File\File; - use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Mapping\PropertyMappingFactory; use Vich\UploaderBundle\Storage\StorageInterface; @@ -20,7 +19,7 @@ abstract class StorageTestCase extends TestCase { /** - * @var PropertyMappingFactory $factory + * @var PropertyMappingFactory */ protected $factory; @@ -65,36 +64,36 @@ public function setUp() ->expects($this->any()) ->method('fromObject') ->with($this->object) - ->will($this->returnValue(array($this->mapping))); + ->will($this->returnValue([$this->mapping])); // and initialize the virtual filesystem - $this->root = vfsStream::setup('vich_uploader_bundle', null, array( - 'uploads' => array( - 'test.txt' => 'some content' - ), - )); + $this->root = vfsStream::setup('vich_uploader_bundle', null, [ + 'uploads' => [ + 'test.txt' => 'some content', + ], + ]); } public function invalidFileProvider() { $file = new File('dummy.file', false); - return array( + return [ // skipped because null - array( null ), + [null], // skipped because not even a file - array( new \DateTime() ), + [new \DateTime()], // skipped because not instance of UploadedFile - array( $file ), - ); + [$file], + ]; } public function emptyFilenameProvider() { - return array( - array( null ), - array( '' ), - ); + return [ + [null], + [''], + ]; } /** @@ -137,6 +136,6 @@ public function testResolveUriWithEmptyFile($filename) protected function getValidUploadDir() { - return $this->root->url() . DIRECTORY_SEPARATOR . 'uploads'; + return $this->root->url().DIRECTORY_SEPARATOR.'uploads'; } } diff --git a/Tests/Templating/Helper/UploadHelperTest.php b/Tests/Templating/Helper/UploadHelperTest.php index bae1d507..54840a1f 100644 --- a/Tests/Templating/Helper/UploadHelperTest.php +++ b/Tests/Templating/Helper/UploadHelperTest.php @@ -27,7 +27,7 @@ public function testGetName() public function testAssetForwardsCallsToTheStorage() { - $obj = new \stdClass; + $obj = new \stdClass(); $this->storage ->expects($this->once()) diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 3005a73f..1a09666c 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -10,7 +10,7 @@ class TestCase extends \PHPUnit_Framework_TestCase protected function getUploadedFileMock() { return $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs(array('lala', 'lala', $mimeType = null, $size = null, $error = 'other than UPLOAD_ERR_OK', $test = true)) + ->setConstructorArgs(['lala', 'lala', $mimeType = null, $size = null, $error = 'other than UPLOAD_ERR_OK', $test = true]) ->getMock(); } @@ -25,7 +25,7 @@ protected function getPropertyMappingMock() } /** - * Creates a mock property mapping factory + * Creates a mock property mapping factory. * * @return PropertyMappingFactory */ diff --git a/Tests/Twig/Extension/UploaderExtensionTest.php b/Tests/Twig/Extension/UploaderExtensionTest.php index 29cf2e59..ae723bd6 100644 --- a/Tests/Twig/Extension/UploaderExtensionTest.php +++ b/Tests/Twig/Extension/UploaderExtensionTest.php @@ -35,7 +35,7 @@ public function testAssetIsRegistered() public function testAssetForwardsCallsToTheHelper() { - $obj = new \stdClass; + $obj = new \stdClass(); $this->helper ->expects($this->once()) diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 3db1ef7c..4d616ebd 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -6,6 +6,6 @@ $loader = require __DIR__.'/../vendor/autoload.php'; -AnnotationRegistry::registerLoader(array($loader, 'loadClass')); +AnnotationRegistry::registerLoader([$loader, 'loadClass']); return $loader; diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index 5068896d..0b89cf60 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -12,7 +12,7 @@ class UploaderExtension extends \Twig_Extension { /** - * @var UploaderHelper $helper + * @var UploaderHelper */ private $helper; @@ -43,20 +43,20 @@ public function getName() */ public function getFunctions() { - return array( - new \Twig_SimpleFunction('vich_uploader_asset', array($this, 'asset')), - ); + return [ + new \Twig_SimpleFunction('vich_uploader_asset', [$this, 'asset']), + ]; } /** * Gets the public path for the file associated with the uploadable * object. * - * @param object $obj The object. - * @param string $fieldName The field name. - * @param string $className The object's class. Mandatory if $obj can't be used to determine it. + * @param object $obj The object + * @param string $fieldName The field name + * @param string $className The object's class. Mandatory if $obj can't be used to determine it * - * @return string The public path. + * @return string The public path */ public function asset($obj, $fieldName, $className = null) { diff --git a/Util/ClassUtils.php b/Util/ClassUtils.php index 3154e1b6..8b19dc6b 100644 --- a/Util/ClassUtils.php +++ b/Util/ClassUtils.php @@ -9,9 +9,9 @@ class ClassUtils /** * Gets class name for the object, taking doctrine proxies into account. * - * @param object $object The object. + * @param object $object The object * - * @return string The FQCN of the given object. + * @return string The FQCN of the given object */ public static function getClass($object) { diff --git a/VichUploaderBundle.php b/VichUploaderBundle.php index 3cac787f..4766cb63 100644 --- a/VichUploaderBundle.php +++ b/VichUploaderBundle.php @@ -4,7 +4,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; - use Vich\UploaderBundle\DependencyInjection\Compiler\RegisterPropelModelsPass; /**