These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\MediaBundle\Command; |
||
15 | |||
16 | use Symfony\Component\Console\Input\InputArgument; |
||
17 | use Symfony\Component\Console\Input\InputInterface; |
||
18 | use Symfony\Component\Console\Input\InputOption; |
||
19 | use Symfony\Component\Console\Output\OutputInterface; |
||
20 | |||
21 | /** |
||
22 | * @final since sonata-project/media-bundle 3.21.0 |
||
23 | */ |
||
24 | class AddMediaCommand extends BaseCommand |
||
0 ignored issues
–
show
|
|||
25 | { |
||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $quiet = false; |
||
30 | |||
31 | /** |
||
32 | * NEXT_MAJOR: remove this property. |
||
33 | * |
||
34 | * @deprecated This property is deprecated since sonata-project/media-bundle 2.4 and will be removed in 4.0 |
||
35 | */ |
||
36 | protected $output; |
||
37 | |||
38 | public function configure(): void |
||
39 | { |
||
40 | $this->setName('sonata:media:add') |
||
41 | ->setDescription('Add a media into the database') |
||
42 | ->setDefinition([ |
||
43 | new InputArgument('providerName', InputArgument::REQUIRED, 'The provider'), |
||
44 | new InputArgument('context', InputArgument::REQUIRED, 'The context'), |
||
45 | new InputArgument('binaryContent', InputArgument::REQUIRED, 'The content'), |
||
46 | |||
47 | new InputOption('description', null, InputOption::VALUE_OPTIONAL, 'The media description field', null), |
||
48 | new InputOption('copyright', null, InputOption::VALUE_OPTIONAL, 'The media copyright field', null), |
||
49 | new InputOption('author', null, InputOption::VALUE_OPTIONAL, 'The media author name field', null), |
||
50 | new InputOption('enabled', null, InputOption::VALUE_OPTIONAL, 'The media enabled field', true), |
||
51 | ]); |
||
52 | } |
||
53 | |||
54 | public function execute(InputInterface $input, OutputInterface $output): int |
||
55 | { |
||
56 | $provider = $input->getArgument('providerName'); |
||
57 | $context = $input->getArgument('context'); |
||
58 | $binaryContent = $input->getArgument('binaryContent'); |
||
59 | |||
60 | $output->writeln(sprintf('Add a new media - context: %s, provider: %s, content: %s', $context, $provider, $binaryContent)); |
||
61 | |||
62 | $media = $this->getMediaManager()->create(); |
||
63 | $media->setBinaryContent($binaryContent); |
||
64 | |||
65 | if ($input->getOption('description')) { |
||
66 | $media->setDescription($input->getOption('description')); |
||
67 | } |
||
68 | |||
69 | if ($input->getOption('copyright')) { |
||
70 | $media->setCopyright($input->getOption('copyright')); |
||
71 | } |
||
72 | |||
73 | if ($input->getOption('author')) { |
||
74 | $media->setAuthorName($input->getOption('author')); |
||
75 | } |
||
76 | |||
77 | if (\in_array($input->getOption('enabled'), [1, true, 'true'], true)) { |
||
78 | $media->setEnabled(true); |
||
79 | } else { |
||
80 | $media->setEnabled(false); |
||
81 | } |
||
82 | |||
83 | $this->getMediaManager()->save($media, $context, $provider); |
||
0 ignored issues
–
show
$context is of type string|array<integer,string>|null , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
The call to
ManagerInterface::save() has too many arguments starting with $provider .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
84 | |||
85 | $output->writeln('done!'); |
||
86 | |||
87 | return 0; |
||
88 | } |
||
89 | } |
||
90 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.