Issues (155)

src/Commands/CommentCommand.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace wapmorgan\UnifiedArchive\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class CommentCommand extends BaseArchiveCommand
10
{
11
    protected static $defaultName = 'archive:comment';
12
13
    protected function configure()
14
    {
15
        parent::configure();
16
        $this
17
            ->setDescription('Sets comment on archive')
18
            ->setHelp('Sets comment on archive.')
19
            ->addArgument('comment', InputArgument::REQUIRED, 'Comment')
20
        ;
21
    }
22
23
    public function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $archive = $this->getArchive($input, $output);
26
        $comment = $input->getArgument('comment');
27
        if (empty($comment)) {
28
            $comment = null;
29
        }
30
31
        if (!empty($previous_comment = $archive->getComment())) {
0 ignored issues
show
Are you sure the assignment to $previous_comment is correct as $archive->getComment() targeting wapmorgan\UnifiedArchive...edArchive::getComment() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
            $output->writeln('Comment "' . $previous_comment . '" replaced', OutputInterface::OUTPUT_RAW);
33
        } else if ($comment === null) {
34
            $output->writeln('Comment deleted', OutputInterface::OUTPUT_RAW);
35
        } else {
36
            $output->writeln('Comment set', OutputInterface::OUTPUT_RAW);
37
        }
38
39
        $archive->setComment($comment);
0 ignored issues
show
It seems like $comment can also be of type string[]; however, parameter $comment of wapmorgan\UnifiedArchive...edArchive::setComment() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $archive->setComment(/** @scrutinizer ignore-type */ $comment);
Loading history...
40
41
        return 0;
42
    }
43
}
44