diff --git a/Command/CheckCommand.php b/Command/CheckCommand.php index 74d68246895bfda736a4f4f37b03bf93f58012bf..e634cb8f8788384f2989c91d2f11c4a6189df2a6 100644 --- a/Command/CheckCommand.php +++ b/Command/CheckCommand.php @@ -17,6 +17,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class CheckCommand extends ContainerAwareCommand { + /** + * {@inheritDoc} + */ protected function configure() { $this @@ -24,6 +27,9 @@ class CheckCommand extends ContainerAwareCommand ->setDescription("Vérifie l'intégrité des fichiers."); } + /** + * {@inheritDoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $manager FileManagerInterface */ diff --git a/Command/CollectGarbageCommand.php b/Command/CollectGarbageCommand.php index c82a8faf651fe39d33288bbdbee7df0cf0934e3d..c38e7197320ca8bd2c117ffcb25a8b1b59cc7ec4 100644 --- a/Command/CollectGarbageCommand.php +++ b/Command/CollectGarbageCommand.php @@ -18,6 +18,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class CollectGarbageCommand extends ContainerAwareCommand { + /** + * {@inheritDoc} + */ protected function configure() { $this @@ -26,6 +29,9 @@ class CollectGarbageCommand extends ContainerAwareCommand ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Affiche ce qui devrait être fait, sans le faire'); } + /** + * {@inheritDoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $manager FileManagerInterface */ diff --git a/Command/CreateCommand.php b/Command/CreateCommand.php index 29941f5084d9e1162b979ee33051e7ebaaef6a35..ba6067c93e0099ac37c8d57b1d5d2dacca8cf54b 100644 --- a/Command/CreateCommand.php +++ b/Command/CreateCommand.php @@ -19,6 +19,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class CreateCommand extends ContainerAwareCommand { + /** + * {@inheritDoc} + */ protected function configure() { $this @@ -30,12 +33,15 @@ class CreateCommand extends ContainerAwareCommand ->addArgument('path', InputArgument::REQUIRED, "Nom du fichier à ajouter, - pour lire l'entrée standard"); } + /** + * {@inheritDoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $em EntityManager */ $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - $id = $written = null; + $written = null; $em->transactional( function () use ($input, $output, $em, &$file, &$written) { @@ -73,7 +79,7 @@ class CreateCommand extends ContainerAwareCommand $manager->completed($file); if ($mimeType) { - $file->setMimeType($mimetype); + $file->setMimeType($mimeType); } if ($metadata) { $file->setMetadata(array_merge($file->getMetadata(), $metadata)); diff --git a/Command/ReadCommand.php b/Command/ReadCommand.php index 5fe31c4ecc6fa0d2ebfcae5ad2f1232efaebd188..0bc03e84fc942a879f98333878d125e030df143a 100644 --- a/Command/ReadCommand.php +++ b/Command/ReadCommand.php @@ -18,6 +18,9 @@ use Symfony\Component\Console\Output\OutputInterface; */ class ReadCommand extends ContainerAwareCommand { + /** + * {@inheritDoc} + */ protected function configure() { $this @@ -29,6 +32,9 @@ class ReadCommand extends ContainerAwareCommand ->addArgument('filepath', InputArgument::OPTIONAL, 'Chemin du fichier dans lequel écrire.'); } + /** + * {@inheritDoc} + */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $manager FileManagerInterface */ diff --git a/Controller/UploadController.php b/Controller/UploadController.php index 48669bb872dda63799178ca0551d25858fd904fa..8044f2f00322d345b39a9991c510f7ab5dc2e50d 100644 --- a/Controller/UploadController.php +++ b/Controller/UploadController.php @@ -130,15 +130,17 @@ class UploadController extends Controller /** * @Route("/{id}/content", name="file_upload_put_content") * @Method("PUT") - * @param Request $request + * @param Request $request * @param UploadedFile $file + * + * @return JsonResponse|Response */ public function putContentAction(Request $request, UploadedFile $file) { try { $this->validateCsrfToken($request); - list($offset, $maxlen, $complete) = $this->handleRangeHeader($request); + [$offset, $maxlen, $complete] = $this->handleRangeHeader($request); // Demande un filehandle plutôt que charger le contenu en mémoire $input = $request->getContent(true); @@ -162,7 +164,7 @@ class UploadController extends Controller */ protected function handleRangeHeader(Request $request) { - if (null === $range = $request->headers->get('Content-Range', null)) { + if (null === $range = $request->headers->get('Content-Range')) { return [0, PHP_INT_MAX, true]; } @@ -171,9 +173,9 @@ class UploadController extends Controller throw new BadRequestHttpException('Invalid Content-Range'); } - $start = intval($matches[1]); - $end = intval($matches[2]); - $total = intval($matches[3]); + $start = (int)$matches[1]; + $end = (int)$matches[2]; + $total = (int)$matches[3]; if ($start < 0 || $start >= $end || $end >= $total) { throw new HttpException(Response::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE); @@ -215,8 +217,10 @@ class UploadController extends Controller /** * @Route("/{id}/content", name="file_upload_get_content") * @Method("GET") - * @param Request $request + * @param Request $request * @param UploadedFile $file + * + * @return UploadedFileResponse */ public function getContentAction(Request $request, UploadedFile $file) { @@ -235,8 +239,10 @@ class UploadController extends Controller /** * @Route("/{id}", name="file_upload_delete") * @Method("DELETE") - * @param Request $request + * @param Request $request * @param UploadedFile $file + * + * @return JsonResponse */ public function deleteAction(Request $request, UploadedFile $file) { @@ -258,7 +264,7 @@ class UploadController extends Controller */ protected function validateCsrfToken(Request $request) { - $token = $this->csrfTokenManager->getToken($request->query->get('token', null)); + $token = $this->csrfTokenManager->getToken($request->query->get('token')); if (!$this->csrfTokenManager->isTokenValid($token)) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid CSRF token'); } diff --git a/Controller/UploadedFileController.php b/Controller/UploadedFileController.php index 23d8bd764c6a9552c9c29a268172f0cfff09f045..d5e2aa56a5a9e7ec2bfc59f7e799c399bd47f0fa 100644 --- a/Controller/UploadedFileController.php +++ b/Controller/UploadedFileController.php @@ -28,6 +28,10 @@ class UploadedFileController extends Controller * @Route("/", name="files") * @Method("GET") * @Template() + * + * @param Request $request + * + * @return array */ public function indexAction(Request $request) { @@ -53,6 +57,10 @@ class UploadedFileController extends Controller * @Route("/{id}", name="files_show") * @Method("GET") * @Template() + * + * @param UploadedFile $uploadedFile + * + * @return array */ public function showAction(UploadedFile $uploadedFile) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 377d3a6e8c19be0211441d286e0fdcbe7165aad2..f01a677cad11c7ec4a668fa70e60a3bc2c00a480 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -30,7 +30,7 @@ class Configuration implements ConfigurationInterface ->ifString() ->then( function ($v) { - $int = intval($v); + $int = (int)$v; if (strpos($v, 'K')) { return 1000 * $int; } diff --git a/DependencyInjection/IrsteaFileUploadExtension.php b/DependencyInjection/IrsteaFileUploadExtension.php index 76aca9c2c950f81c94662244f014ff6daf3a7955..239afd4f8ee7e7aa13b567ca46b97a17b2454823 100644 --- a/DependencyInjection/IrsteaFileUploadExtension.php +++ b/DependencyInjection/IrsteaFileUploadExtension.php @@ -12,6 +12,9 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +/** + * {@inheritDoc} + */ class IrsteaFileUploadExtension extends Extension implements PrependExtensionInterface { /** diff --git a/Entity/Repository/UploadedFileRepository.php b/Entity/Repository/UploadedFileRepository.php index 42d2f9db023dff07643a4bd49565555706b553e6..9099c43121c3d6173319c3af3ff03ae52fdd6838 100644 --- a/Entity/Repository/UploadedFileRepository.php +++ b/Entity/Repository/UploadedFileRepository.php @@ -17,6 +17,7 @@ use Irstea\FileUploadBundle\Exception\RejectedFileException; use Irstea\FileUploadBundle\FileUploadEvents; use Irstea\FileUploadBundle\Model\FileManagerInterface; use Irstea\FileUploadBundle\Model\UploadedFileInterface; +use Psr\Log\LoggerAwareTrait; use Psr\Log\LogLevel; use Rhumsaa\Uuid\Uuid; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -28,7 +29,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; */ class UploadedFileRepository extends EntityRepository implements FileManagerInterface { - use \Psr\Log\LoggerAwareTrait; + use LoggerAwareTrait; /** * @var Filesystem diff --git a/Entity/UploadedFile.php b/Entity/UploadedFile.php index 5dd9797ac400e7dfed1ff39061c596562ea14a3f..8869f83c1b32830cefd0a0519c3dd971a82ac08d 100644 --- a/Entity/UploadedFile.php +++ b/Entity/UploadedFile.php @@ -62,19 +62,19 @@ class UploadedFile implements UploadedFileInterface * @ORM\Column(type="string", length=255, nullable=true) * @var string */ - private $mimeType = null; + private $mimeType; /** * @ORM\Column(type="integer", nullable=true) * @var int */ - private $size = null; + private $size; /** * @ORM\Column(type="string", length=64, nullable=true) * @var string */ - private $checksum = null; + private $checksum; /** * @ORM\Column(type="string", length=10) @@ -104,13 +104,13 @@ class UploadedFile implements UploadedFileInterface * @ORM\Column(type="json_array", nullable=true) * @var array */ - private $metadata = null; + private $metadata; /** * @ORM\Column(type="string", length=256, nullable=true) * @var string */ - private $description = null; + private $description; /** * @var Filesystem @@ -120,7 +120,7 @@ class UploadedFile implements UploadedFileInterface /** Contient le nom de chemin local. * @var string */ - private $localTempPath = null; + private $localTempPath; /** Crée un UploadedFile. * @internal @@ -170,7 +170,7 @@ class UploadedFile implements UploadedFileInterface */ public function getActualPath() { - if (!isset($this->actualPath)) { + if (null === $this->actualPath) { $this->actualPath = $this->path; } @@ -266,7 +266,8 @@ class UploadedFile implements UploadedFileInterface self::ETAT_NORMAL, self::ETAT_ORPHELIN, self::ETAT_REJETE, - ] + ], + true )) { throw new InvalidArgumentException(sprintf("Etat invalide: '%s'", (string)$etat)); } diff --git a/Exception/RejectedFileException.php b/Exception/RejectedFileException.php index 7004211720bad79a413e5c19857783d84428b2dc..064b6d6e1e463b0c02efce390eaadd0293887c22 100644 --- a/Exception/RejectedFileException.php +++ b/Exception/RejectedFileException.php @@ -20,10 +20,12 @@ class RejectedFileException extends RuntimeException implements Exception protected $uploadedFile; /** - * @param UploadedFileInterface $file - * @param string $message - * @param int $code - * @param \Exception $previous + * @param UploadedFileInterface $uploadedFile + * @param string $message + * @param int $code + * @param \Exception $previous + * + * @internal param UploadedFileInterface $file */ public function __construct(UploadedFileInterface $uploadedFile, $message, $code = 0, $previous = null) { diff --git a/Form/Type/FileUploadType.php b/Form/Type/FileUploadType.php index df9c89743e0c16043dc58a6365cde197325278df..9272074af86fe10ee939c0652d44004453fa6082 100644 --- a/Form/Type/FileUploadType.php +++ b/Form/Type/FileUploadType.php @@ -10,6 +10,7 @@ use Irstea\FileUploadBundle\Form\DataTranformer\UploadedFileTransformer; use Irstea\FileUploadBundle\Model\FileManagerInterface; use Irstea\FileUploadBundle\Validation\FileMimeType; use Irstea\FileUploadBundle\Validation\FileSize; +use Irstea\ThemeBundle\Form\AbstractJQueryWidgetTrait; use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener; @@ -36,7 +37,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; */ class FileUploadType extends AbstractType { - use \Irstea\ThemeBundle\Form\AbstractJQueryWidgetTrait; + use AbstractJQueryWidgetTrait; /** Routeur. * @var Router @@ -125,7 +126,10 @@ class FileUploadType extends AbstractType /** Ajoute des contraintes de validation correspondants aux paramètres du champ. * @todo Implémenter min_file_size, max_file_size && accept_file_types. * + * @param OptionsResolver $options * @param mixed $constraints + * + * @return array|mixed */ protected function addConstraints(OptionsResolver $options, $constraints) { diff --git a/Http/UploadedFileResponse.php b/Http/UploadedFileResponse.php index 10c0e13ad09bc2d67c9d6997091fb4cc888769c7..9edcfa19a0bedde5f7144a0241056b4859ab4fb8 100644 --- a/Http/UploadedFileResponse.php +++ b/Http/UploadedFileResponse.php @@ -162,7 +162,7 @@ class UploadedFileResponse extends Response $range = $request->headers->get('Range'); $fileSize = $this->file->getSize(); - list($start, $end) = explode('-', substr($range, 6), 2) + [0]; + [$start, $end] = explode('-', substr($range, 6), 2) + [0]; $end = ('' === $end) ? $fileSize - 1 : (int)$end; diff --git a/IrsteaFileUploadBundle.php b/IrsteaFileUploadBundle.php index 04e1e1dc4f53175cd686720960a71975028d355e..2275430fa697a319474a3e91692ad3b20c90f0ba 100644 --- a/IrsteaFileUploadBundle.php +++ b/IrsteaFileUploadBundle.php @@ -8,6 +8,9 @@ namespace Irstea\FileUploadBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +/** + * {@inheritDoc} + */ class IrsteaFileUploadBundle extends Bundle { } diff --git a/Listener/CreationDataListener.php b/Listener/CreationDataListener.php index ae40523d43260efa4880cb241f7dbcacec2f13ae..c9d1d883db789a856b54267920f7218c559eb5b9 100644 --- a/Listener/CreationDataListener.php +++ b/Listener/CreationDataListener.php @@ -34,6 +34,7 @@ class CreationDataListener } /** + * @param UploadedFileInterface $file * @param LifecycleEventArgs $event */ public function prePersist(UploadedFileInterface $file, LifecycleEventArgs $event) diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js index 2d490895afde038cf0afaac412194651f06ccdab..373b5cc14836d192a46b811763f294b498a10431 100644 --- a/Resources/js/widget/file_upload.js +++ b/Resources/js/widget/file_upload.js @@ -18,7 +18,7 @@ } else { unit = ''; } - 'UPLOADING !' + return Translator.trans('file_size(%size%,%unit%)', {size: size, unit: unit}, 'file_upload'); }, formatBitrate = function (rate) { diff --git a/Service/FileUrlGeneratorInterface.php b/Service/FileUrlGeneratorInterface.php index b70b9acbaa37e6586804c78f24c6c35b2ef15133..71077640d81264a14b8c56f72c29d6e1285eda58 100644 --- a/Service/FileUrlGeneratorInterface.php +++ b/Service/FileUrlGeneratorInterface.php @@ -16,8 +16,8 @@ interface FileUrlGeneratorInterface /** * Génère une URL sécurisée pour un fichier. * - * @param string $idFile identifiant du fichier pour lequel générer l'URL - * @param string|bool $referenceType type d'URL à générer + * @param string $idFile identifiant du fichier pour lequel générer l'URL + * @param bool|int|string $referenceType type d'URL à générer * * @return string L'url générée */ diff --git a/Tests/Entity/UploadedFileTest.php b/Tests/Entity/UploadedFileTest.php index b88cf8667bf26183156afaf65a6884b93e2d402d..deced93557b53d5de532105c39b20a4f34a5c40a 100644 --- a/Tests/Entity/UploadedFileTest.php +++ b/Tests/Entity/UploadedFileTest.php @@ -37,7 +37,7 @@ class UploadedFileTest extends PHPUnit_Framework_TestCase */ public function testIsSafePath($isSafe, $path) { - $this->assertEquals($isSafe, UploadedFile::isSafePath($path)); + static::assertEquals($isSafe, UploadedFile::isSafePath($path)); } public function getIsSafePathvalues() @@ -59,6 +59,6 @@ class UploadedFileTest extends PHPUnit_Framework_TestCase $this->file->moveTo('machin/chose/'); - $this->assertEquals('machin/chose/muche', $this->file->getPath()); + static::assertEquals('machin/chose/muche', $this->file->getPath()); } } diff --git a/Tests/Form/DataTranformer/UploadedFileTransformerTest.php b/Tests/Form/DataTranformer/UploadedFileTransformerTest.php index 3c4cb679808d334811c76212e9c7e462ad41ef6f..0b109772688622ead215dac1c590ee46ad5a9cb9 100644 --- a/Tests/Form/DataTranformer/UploadedFileTransformerTest.php +++ b/Tests/Form/DataTranformer/UploadedFileTransformerTest.php @@ -10,6 +10,7 @@ use Irstea\FileUploadBundle\Form\DataTranformer\UploadedFileTransformer; use Irstea\FileUploadBundle\Model\UploadedFileInterface; use PHPUnit_Framework_MockObject_MockObject; use PHPUnit_Framework_TestCase; +use Irstea\FileUploadBundle\Model\FileManagerInterface; /** * Generated by PHPUnit_SkeletonGenerator on 2015-01-27 at 11:36:06. @@ -32,7 +33,7 @@ class UploadedFileTransformerTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->fileManager = $this->getMock('\Irstea\FileUploadBundle\Model\FileManagerInterface'); + $this->fileManager = $this->getMock(FileManagerInterface::class); $this->transformer = new UploadedFileTransformer($this->fileManager, true); } @@ -46,7 +47,7 @@ class UploadedFileTransformerTest extends PHPUnit_Framework_TestCase */ public function testEmptyValues($expected, $method, $value) { - $this->assertEquals($expected, $this->transformer->$method($value)); + static::assertEquals($expected, $this->transformer->$method($value)); } public function getEmptyValues() @@ -72,11 +73,11 @@ class UploadedFileTransformerTest extends PHPUnit_Framework_TestCase public function testTransformFile() { - $file = $this->getMock('\Irstea\FileUploadBundle\Model\UploadedFileInterface'); + $file = $this->getMock(UploadedFileInterface::class); - $file->expects($this->once())->method('toArray')->willReturn(['bla']); + $file->expects(static::once())->method('toArray')->willReturn(['bla']); - $this->assertEquals(['bla'], $this->transformer->transformFile($file)); + static::assertEquals(['bla'], $this->transformer->transformFile($file)); } /** @@ -89,38 +90,38 @@ class UploadedFileTransformerTest extends PHPUnit_Framework_TestCase public function testReverseTransformFileNoId() { - $this->assertNull($this->transformer->reverseTransformFile(['desc' => ''])); + static::assertNull($this->transformer->reverseTransformFile(['desc' => ''])); } public function testReverseTransformFile() { - $file = $this->getMock('\Irstea\FileUploadBundle\Model\UploadedFileInterface'); + $file = $this->getMock(UploadedFileInterface::class); - $this->fileManager->expects($this->once())->method('get')->with('FOO')->willReturn($file); - $file->expects($this->once())->method('isOrphelin')->willReturn(true); - $file->expects($this->once())->method('setEtat')->with(UploadedFileInterface::ETAT_NORMAL); - $file->expects($this->once())->method('setDescription')->with('truc'); + $this->fileManager->expects(static::once())->method('get')->with('FOO')->willReturn($file); + $file->expects(static::once())->method('isOrphelin')->willReturn(true); + $file->expects(static::once())->method('setEtat')->with(UploadedFileInterface::ETAT_NORMAL); + $file->expects(static::once())->method('setDescription')->with('truc'); - $this->assertSame($file, $this->transformer->reverseTransformFile(['id' => 'FOO', 'description' => 'truc'])); + static::assertSame($file, $this->transformer->reverseTransformFile(['id' => 'FOO', 'description' => 'truc'])); } public function testTransformEmptyEntries() { - $file = $this->getMock('\Irstea\FileUploadBundle\Model\UploadedFileInterface'); - $file->expects($this->any())->method('toArray')->willReturn(['bla']); + $file = $this->getMock(UploadedFileInterface::class); + $file->expects(static::any())->method('toArray')->willReturn(['bla']); $result = $this->transformer->transform([$file, null, $file]); - $this->assertEquals([['bla'], ['bla']], $result); + static::assertEquals([['bla'], ['bla']], $result); } public function testReverseTransformEmptyEntries() { - $file = $this->getMock('\Irstea\FileUploadBundle\Model\UploadedFileInterface'); - $this->fileManager->expects($this->any())->method('get')->with('FOO')->willReturn($file); + $file = $this->getMock(UploadedFileInterface::class); + $this->fileManager->expects(static::any())->method('get')->with('FOO')->willReturn($file); $result = $this->transformer->reverseTransform([['id' => 'FOO'], null, ['description' => 'muche'], ['id' => 'FOO']]); - $this->assertEquals([$file, $file], $result); + static::assertEquals([$file, $file], $result); } } diff --git a/Tests/Listener/UploadedFileListenerTest.php b/Tests/Listener/UploadedFileListenerTest.php index f73abcfb76460b950aa3bc06bd1ecf2f8337a7e6..acfaca0cbc4fe715a96af6bffe9d244871d651c5 100644 --- a/Tests/Listener/UploadedFileListenerTest.php +++ b/Tests/Listener/UploadedFileListenerTest.php @@ -10,6 +10,10 @@ use Doctrine\ORM\Event\LifecycleEventArgs; use Gaufrette\Exception\FileNotFound; use PHPUnit_Framework_MockObject_MockObject; use PHPUnit_Framework_TestCase; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\UnitOfWork; +use Irstea\FileUploadBundle\Entity\UploadedFile; +use Gaufrette\Filesystem; /** * Generated by PHPUnit_SkeletonGenerator on 2015-01-29 at 14:56:00. @@ -52,26 +56,26 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->filesystem = $this->getMockBuilder('\Gaufrette\Filesystem') + $this->filesystem = $this->getMockBuilder(Filesystem::class) ->disableOriginalConstructor() ->getMock(); $this->listener = new UploadedFileListener($this->filesystem); - $this->file = $this->getMockBuilder('\Irstea\FileUploadBundle\Entity\UploadedFile') + $this->file = $this->getMockBuilder(UploadedFile::class) ->setMethods(['setFilesystem', 'getPath']) ->getMockForAbstractClass(); - $this->unitOfWork = $this->getMockBuilder('\Doctrine\ORM\UnitOfWork') + $this->unitOfWork = $this->getMockBuilder(UnitOfWork::class) ->disableOriginalConstructor() ->setMethods(['getEntityChangeSet']) ->getMock(); - $this->om = $this->getMockBuilder('\Doctrine\ORM\EntityManager') + $this->om = $this->getMockBuilder(EntityManager::class) ->setMethods(['getUnitOfWork']) ->disableOriginalConstructor() ->getMock(); - $this->om->expects($this->any())->method('getUnitOfWork')->willReturn($this->unitOfWork); + $this->om->expects(static::any())->method('getUnitOfWork')->willReturn($this->unitOfWork); $this->event = new LifecycleEventArgs($this->file, $this->om); } @@ -82,7 +86,7 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testPostLoad() { - $this->file->expects($this->once())->method('setFilesystem')->with($this->identicalTo($this->filesystem)); + $this->file->expects(static::once())->method('setFilesystem')->with(static::identicalTo($this->filesystem)); $this->listener->postLoad($this->file, $this->event); } @@ -92,9 +96,9 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testPostUpdateNoPathChange() { - $this->unitOfWork->expects($this->once())->method('getEntityChangeSet')->with($this->file)->willReturn([]); + $this->unitOfWork->expects(static::once())->method('getEntityChangeSet')->with($this->file)->willReturn([]); - $this->filesystem->expects($this->never())->method('rename'); + $this->filesystem->expects(static::never())->method('rename'); $this->listener->postUpdate($this->file, $this->event); } @@ -104,11 +108,11 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testPostUpdatePathChanged() { - $this->unitOfWork->expects($this->once())->method('getEntityChangeSet')->with($this->file)->willReturn( + $this->unitOfWork->expects(static::once())->method('getEntityChangeSet')->with($this->file)->willReturn( ['path' => ['before', 'after']] ); - $this->filesystem->expects($this->once())->method('rename')->with('before', 'after'); + $this->filesystem->expects(static::once())->method('rename')->with('before', 'after'); $this->listener->postUpdate($this->file, $this->event); } @@ -118,10 +122,10 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testRemove() { - $this->file->expects($this->any())->method('getId')->willReturn('bla'); - $this->file->expects($this->once())->method('getPath')->willReturn('foobar'); + $this->file->expects(static::any())->method('getId')->willReturn('bla'); + $this->file->expects(static::once())->method('getPath')->willReturn('foobar'); - $this->filesystem->expects($this->once())->method('delete')->with('foobar'); + $this->filesystem->expects(static::once())->method('delete')->with('foobar'); $this->listener->preRemove($this->file, $this->event); $this->listener->postRemove($this->file, $this->event); @@ -132,10 +136,10 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testRemoveIgnoreFileNotFound() { - $this->file->expects($this->any())->method('getId')->willReturn('bla'); - $this->file->expects($this->once())->method('getPath')->willReturn('foobar'); + $this->file->expects(static::any())->method('getId')->willReturn('bla'); + $this->file->expects(static::once())->method('getPath')->willReturn('foobar'); - $this->filesystem->expects($this->once())->method('delete')->with('foobar')->willThrowException(new FileNotFound('foobar')); + $this->filesystem->expects(static::once())->method('delete')->with('foobar')->willThrowException(new FileNotFound('foobar')); $this->listener->preRemove($this->file, $this->event); $this->listener->postRemove($this->file, $this->event); @@ -147,10 +151,10 @@ class UploadedFileListenerTest extends PHPUnit_Framework_TestCase */ public function testRemovePropagateOtherExceptions() { - $this->file->expects($this->any())->method('getId')->willReturn('bla'); - $this->file->expects($this->once())->method('getPath')->willReturn('foobar'); + $this->file->expects(static::any())->method('getId')->willReturn('bla'); + $this->file->expects(static::once())->method('getPath')->willReturn('foobar'); - $this->filesystem->expects($this->once())->method('delete')->with('foobar')->willThrowException(new \InvalidArgumentException()); + $this->filesystem->expects(static::once())->method('delete')->with('foobar')->willThrowException(new \InvalidArgumentException()); $this->listener->preRemove($this->file, $this->event); $this->listener->postRemove($this->file, $this->event); diff --git a/Tests/Listener/VirusScannerListenerTest.php b/Tests/Listener/VirusScannerListenerTest.php index fc98d766e4cc9aabec357210aa9d203a6881208c..3934b50ef5361344942d1615a1222d2c47b8616a 100644 --- a/Tests/Listener/VirusScannerListenerTest.php +++ b/Tests/Listener/VirusScannerListenerTest.php @@ -12,6 +12,7 @@ use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent; use Irstea\FileUploadBundle\Listener\VirusScannerListener; use PHPUnit_Framework_MockObject_MockObject; use PHPUnit_Framework_TestCase; +use Irstea\FileUploadBundle\Model\UploadedFileInterface; /** * Generated by PHPUnit_SkeletonGenerator on 2015-01-29 at 14:43:16. @@ -38,11 +39,14 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase */ protected $file; + /** + * {@inheritDoc} + */ protected function setUp() { - $this->file = $this->getMock('\Irstea\FileUploadBundle\Model\UploadedFileInterface'); - $this->file->expects($this->once())->method('getLocalPath')->willReturn('foopath'); - $this->file->expects($this->once())->method('getMetadata')->willReturn([]); + $this->file = $this->getMock(UploadedFileInterface::class); + $this->file->expects(static::once())->method('getLocalPath')->willReturn('foopath'); + $this->file->expects(static::once())->method('getMetadata')->willReturn([]); $this->event = new FileUploadCompleteEvent($this->file); @@ -58,9 +62,9 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase ['foopath'], [] ); - $this->scanner->expects($this->once())->method('scan')->with(['foopath'])->willReturn($result); + $this->scanner->expects(static::once())->method('scan')->with(['foopath'])->willReturn($result); - $this->file->expects($this->once())->method('setMetadata')->with(['virus_scanner' => ['has_virus' => false]]); + $this->file->expects(static::once())->method('setMetadata')->with(['virus_scanner' => ['has_virus' => false]]); $this->listener->onFileUploadCompleted($this->event); } @@ -75,9 +79,9 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase ['foopath'], [new Detection('foopath', Detection::TYPE_VIRUS, 'BAR')] ); - $this->scanner->expects($this->once())->method('scan')->with(['foopath'])->willReturn($result); + $this->scanner->expects(static::once())->method('scan')->with(['foopath'])->willReturn($result); - $this->file->expects($this->once())->method('setMetadata')->with( + $this->file->expects(static::once())->method('setMetadata')->with( ['virus_scanner' => ['has_virus' => true, 'detected' => 'BAR']] ); @@ -94,9 +98,9 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase ['foopath'], [new Detection('foopath', Detection::TYPE_VIRUS)] ); - $this->scanner->expects($this->once())->method('scan')->with(['foopath'])->willReturn($result); + $this->scanner->expects(static::once())->method('scan')->with(['foopath'])->willReturn($result); - $this->file->expects($this->once())->method('setMetadata')->with( + $this->file->expects(static::once())->method('setMetadata')->with( ['virus_scanner' => ['has_virus' => true]] ); diff --git a/Tests/Utils/MimeTypeIconTest.php b/Tests/Utils/MimeTypeIconTest.php index b299324d08a72d3fc47dc151dec256a6b1b61f85..7d03bd03a880af5d39f0dfca1554ec28f67ab0df 100644 --- a/Tests/Utils/MimeTypeIconTest.php +++ b/Tests/Utils/MimeTypeIconTest.php @@ -23,7 +23,7 @@ class MimeTypeIconTest extends PHPUnit_Framework_TestCase */ public function testGetMimeTypeIcon($expected, $input) { - $this->assertEquals($expected, MimeTypeIcon::getMimeTypeIcon($input)); + static::assertEquals($expected, MimeTypeIcon::getMimeTypeIcon($input)); } public function getTestValues() diff --git a/Twig/FileUploadExtension.php b/Twig/FileUploadExtension.php index 3f3dcc38d9cd03f279818a48f17c1728c27e077b..bb75dc1d2df26d56dcfa33bd78ee7913d3b07520 100644 --- a/Twig/FileUploadExtension.php +++ b/Twig/FileUploadExtension.php @@ -35,6 +35,7 @@ class FileUploadExtension extends Twig_Extension /** * @param TranslatorInterface $translator + * @param FileUrlGeneratorInterface $urlGenerator */ public function __construct(TranslatorInterface $translator, FileUrlGeneratorInterface $urlGenerator) { @@ -118,8 +119,8 @@ class FileUploadExtension extends Twig_Extension /** Genère un URL sécurisée pour télécharger un fichier. * Usage : `{{ irstea_file_path(file.id) }}`. * - * @param string $idFile - * @param string|bool $referenceType + * @param string $idFile + * @param bool|int|string $referenceType * * @return string */ @@ -182,8 +183,8 @@ class FileUploadExtension extends Twig_Extension } $formatter = NumberFormatter::create($locale, NumberFormatter::DECIMAL); - $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, null !== $precision ? $precision : 0); - $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, null !== $precision ? $precision : $defaultPrecision); + $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $precision ?? 0); + $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $precision ?? $defaultPrecision); return $this->translator->trans( 'file_size(%size%,%unit%)', diff --git a/Validation/FileMimeType.php b/Validation/FileMimeType.php index daf09060a339990fa4143963da89a5615f3119cf..b8b1897b77ba7348a1cb4911ce4c8aca03bdbca3 100644 --- a/Validation/FileMimeType.php +++ b/Validation/FileMimeType.php @@ -16,7 +16,7 @@ class FileMimeType extends Constraint /** * @var string */ - public $acceptedMimeTypes = null; + public $acceptedMimeTypes; /** * @var string diff --git a/Validation/FileSize.php b/Validation/FileSize.php index 9d9f978f983b9bb4b498d9325d20a3675130609a..c995ff09c8493b2bef83b33d190279056c72c5b0 100644 --- a/Validation/FileSize.php +++ b/Validation/FileSize.php @@ -16,12 +16,12 @@ class FileSize extends Constraint /** * @var int|null */ - public $min = null; + public $min; /** * @var int|null */ - public $max = null; + public $max; /** * @var string