These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\MediaBundle\Command; |
||
4 | |||
5 | use Doctrine\ORM\EntityManager; |
||
6 | use Doctrine\ORM\EntityManagerInterface; |
||
7 | use ImagickException; |
||
8 | use Kunstmaan\MediaBundle\Entity\Media; |
||
9 | use Kunstmaan\MediaBundle\Helper\Transformer\PdfTransformer; |
||
10 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
||
11 | use Symfony\Component\Console\Input\InputInterface; |
||
12 | use Symfony\Component\Console\Output\OutputInterface; |
||
13 | |||
14 | /** |
||
15 | * @final since 5.1 |
||
16 | * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages |
||
17 | */ |
||
18 | class CreatePdfPreviewCommand extends ContainerAwareCommand |
||
19 | { |
||
20 | /** |
||
21 | * @var EntityManager |
||
22 | */ |
||
23 | private $em; |
||
24 | |||
25 | /** |
||
26 | * @var PdfTransformer |
||
27 | */ |
||
28 | private $pdfTransformer; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $webRoot; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $enablePdfPreview; |
||
39 | |||
40 | /** |
||
41 | * @param EntityManagerInterface|null $em |
||
42 | * @param PdfTransformer|null $mediaManager |
||
0 ignored issues
–
show
|
|||
43 | */ |
||
44 | public function __construct(/* EntityManagerInterface */ $em = null, /* PdfTransformer */ $pdfTransformer = null, $webRoot = null, $enablePdfPreview = null) |
||
45 | { |
||
46 | parent::__construct(); |
||
47 | |||
48 | if (!$em instanceof EntityManagerInterface) { |
||
49 | @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED); |
||
50 | |||
51 | $this->setName(null === $em ? 'kuma:media:create-pdf-previews' : $em); |
||
52 | |||
53 | return; |
||
54 | } |
||
55 | |||
56 | $this->em = $em; |
||
0 ignored issues
–
show
$em is of type object<Doctrine\ORM\EntityManagerInterface> , but the property $em was declared to be of type object<Doctrine\ORM\EntityManager> . Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly. Either this assignment is in error or an instanceof check should be added for that assignment. class Alien {}
class Dalek extends Alien {}
class Plot
{
/** @var Dalek */
public $villain;
}
$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
$plot->villain = $alien;
}
Loading history...
|
|||
57 | $this->pdfTransformer = $pdfTransformer; |
||
58 | $this->webRoot = $webRoot; |
||
59 | $this->enablePdfPreview = $enablePdfPreview; |
||
60 | } |
||
61 | |||
62 | protected function configure() |
||
63 | { |
||
64 | parent::configure(); |
||
65 | |||
66 | $this |
||
67 | ->setName('kuma:media:create-pdf-previews') |
||
68 | ->setDescription('Create preview images for PDFs that have already been uploaded') |
||
69 | ->setHelp( |
||
70 | 'The <info>kuma:media:create-pdf-previews</info> command can be used to create preview images for PDFs that have already been uploaded.' |
||
71 | ); |
||
72 | } |
||
73 | |||
74 | public function execute(InputInterface $input, OutputInterface $output) |
||
75 | { |
||
76 | if (null === $this->em) { |
||
77 | $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
78 | $this->pdfTransformer = $this->getContainer()->get('kunstmaan_media.pdf_transformer'); |
||
79 | $this->webRoot = $this->getContainer()->getParameter('kunstmaan_media.web_root'); |
||
80 | $this->enablePdfPreview = $this->getContainer()->getParameter('kunstmaan_media.enable_pdf_preview'); |
||
81 | } |
||
82 | |||
83 | $output->writeln('Creating PDF preview images...'); |
||
84 | |||
85 | /** |
||
86 | * @var EntityManager |
||
87 | */ |
||
88 | $medias = $this->em->getRepository('KunstmaanMediaBundle:Media')->findBy( |
||
89 | array('contentType' => 'application/pdf', 'deleted' => false) |
||
90 | ); |
||
91 | /** @var Media $media */ |
||
92 | foreach ($medias as $media) { |
||
93 | try { |
||
94 | $this->pdfTransformer->apply($this->webRoot . $media->getUrl()); |
||
95 | } catch (ImagickException $e) { |
||
96 | $output->writeln('<comment>'.$e->getMessage().'</comment>'); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $output->writeln('<info>PDF preview images have been created.</info>'); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Checks whether the command is enabled or not in the current environment. |
||
105 | * |
||
106 | * Override this to check for x or y and return false if the command can not |
||
107 | * run properly under the current conditions. |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function isEnabled() |
||
112 | { |
||
113 | if (null === $this->enablePdfPreview) { |
||
114 | $this->enablePdfPreview = $this->getContainer()->getParameter('kunstmaan_media.enable_pdf_preview'); |
||
115 | } |
||
116 | |||
117 | return $this->enablePdfPreview; |
||
118 | } |
||
119 | } |
||
120 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.