This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 | namespace BestIt\LicenseCheck\Command; |
||
6 | |||
7 | use BestIt\LicenseCheck\Checker; |
||
8 | use BestIt\LicenseCheck\Command\Exception\CommandException; |
||
9 | use BestIt\LicenseCheck\Configuration\ConfigurationLoader; |
||
10 | use BestIt\LicenseCheck\Configuration\Exception\ConfigurationNotFoundException; |
||
11 | use BestIt\LicenseCheck\Configuration\Exception\ConfigurationParseException; |
||
12 | use Symfony\Component\Console\Command\Command; |
||
13 | use Symfony\Component\Console\Input\InputArgument; |
||
14 | use Symfony\Component\Console\Input\InputInterface; |
||
15 | use Symfony\Component\Console\Input\InputOption; |
||
16 | use Symfony\Component\Console\Output\OutputInterface; |
||
17 | use function defined; |
||
18 | |||
19 | /** |
||
20 | * Command to check package licenses. |
||
21 | * |
||
22 | * @author best it AG <[email protected]> |
||
23 | * @package BestIt\LicenseCheck\Command |
||
24 | */ |
||
25 | class LicenseCheckCommand extends Command |
||
26 | { |
||
27 | /** |
||
28 | * Constant for the directory cli argument. |
||
29 | * |
||
30 | * @var string ARGUMENT_DIRECTORY |
||
31 | */ |
||
32 | private const ARGUMENT_DIRECTORY = 'directory'; |
||
33 | |||
34 | /** |
||
35 | * Constant for the configuration cli option. |
||
36 | * |
||
37 | * @var string OPTION_CONFIGURATION |
||
38 | */ |
||
39 | private const OPTION_CONFIGURATION = 'configuration'; |
||
40 | |||
41 | /** |
||
42 | * Constant for the ignore-errors cli option. |
||
43 | * |
||
44 | * @var string OPTION_IGNORE_ERRORS |
||
45 | */ |
||
46 | private const OPTION_IGNORE_ERRORS = 'ignore-errors'; |
||
47 | |||
48 | /** |
||
49 | * Dependency to the checker class which do the license validation. |
||
50 | * |
||
51 | * @var Checker $checker |
||
52 | */ |
||
53 | private Checker $checker; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | |||
55 | /** |
||
56 | * Dependency to the loader to get the configuration object. |
||
57 | * |
||
58 | * @var ConfigurationLoader $configurationLoader |
||
59 | */ |
||
60 | private ConfigurationLoader $configurationLoader; |
||
61 | |||
62 | /** |
||
63 | * Create license check command instance. |
||
64 | * |
||
65 | * @param Checker $checker Dependency to the checker class which do the license validation. |
||
66 | * @param ConfigurationLoader $configurationLoader Dependency to the loader to get the configuration object. |
||
67 | */ |
||
68 | public function __construct(Checker $checker, ConfigurationLoader $configurationLoader) |
||
69 | { |
||
70 | $this->checker = $checker; |
||
71 | $this->configurationLoader = $configurationLoader; |
||
72 | |||
73 | parent::__construct('license-check'); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Add needed arguments and options to the command. |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | protected function configure(): void |
||
82 | { |
||
83 | $this |
||
84 | ->setDescription('Tool to check licenses of used packages.') |
||
85 | ->addArgument( |
||
86 | self::ARGUMENT_DIRECTORY, |
||
87 | InputArgument::OPTIONAL, |
||
88 | __DIR__, |
||
89 | ) |
||
90 | ->addOption( |
||
91 | self::OPTION_CONFIGURATION, |
||
92 | 'c', |
||
93 | InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
||
94 | 'List of configuration files.', |
||
95 | ) |
||
96 | ->addOption( |
||
97 | self::OPTION_IGNORE_ERRORS, |
||
98 | null, |
||
99 | InputOption::VALUE_NONE, |
||
100 | 'Don\'t return an error code.', |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Execution method for the cli command. |
||
106 | * |
||
107 | * @param InputInterface $input |
||
108 | * @param OutputInterface $output |
||
109 | * |
||
110 | * @throws ConfigurationNotFoundException Exception if configuration is not found. |
||
111 | * @throws ConfigurationParseException Exception if configuration cannot be parsed. |
||
112 | * @throws CommandException Thrown if directory is not readable |
||
113 | * |
||
114 | * @return int |
||
115 | */ |
||
116 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
117 | { |
||
118 | if (!is_string($workingDirectory = $input->getArgument(self::ARGUMENT_DIRECTORY))) { |
||
119 | $workingDirectory = getcwd(); |
||
120 | } |
||
121 | |||
122 | if (!is_string($workingDirectory)) { |
||
123 | throw new CommandException('Cannot read working directory.'); |
||
124 | } |
||
125 | |||
126 | $configFiles = $input->getOption(self::OPTION_CONFIGURATION); |
||
127 | |||
128 | assert(is_array($configFiles)); |
||
129 | if (count($configFiles) === 0) { |
||
130 | $configFiles[] = $workingDirectory . '/license-check.yml'; |
||
131 | } |
||
132 | |||
133 | $configuration = $this->configurationLoader->load($configFiles); |
||
134 | |||
135 | $resultSet = $this->checker->validate($configuration, $workingDirectory); |
||
136 | |||
137 | $resultCode = defined('static::SUCCESS') ? static::SUCCESS : 0; |
||
138 | |||
139 | if ($resultSet->isPassed()) { |
||
140 | $output->writeln('<info>License check passed!</info>'); |
||
141 | } else { |
||
142 | if (!$input->getOption(self::OPTION_IGNORE_ERRORS)) { |
||
143 | $resultCode = defined('static::FAILURE') ? static::FAILURE : 1; |
||
144 | } |
||
145 | |||
146 | foreach ($resultSet->getViolations() as $violation) { |
||
147 | $output->writeln( |
||
148 | sprintf( |
||
149 | '<comment>%s</comment>', |
||
150 | $violation, |
||
151 | ), |
||
152 | ); |
||
153 | } |
||
154 | |||
155 | $output->writeln('<error>License check failed!</error>'); |
||
156 | } |
||
157 | |||
158 | return $resultCode; |
||
159 | } |
||
160 | } |
||
161 |