1 | <?php namespace Packedge\Workbench\Console\Package; |
||
14 | class NewCommand extends BaseCommand |
||
15 | { |
||
16 | /** |
||
17 | * The console command name. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name = 'package:new'; |
||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Create a new package'; |
||
28 | /** |
||
29 | * @var Parser |
||
30 | */ |
||
31 | protected $parser; |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $packageDescription; |
||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $packageName; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $licenceName; |
||
44 | /** |
||
45 | * @var Package |
||
46 | */ |
||
47 | private $package; |
||
48 | /** |
||
49 | * @var EventManager |
||
50 | */ |
||
51 | private $manager; |
||
52 | |||
53 | /** |
||
54 | * @param EventManager $manager |
||
55 | * @param Package $package |
||
56 | */ |
||
57 | 3 | public function __construct(EventManager $manager, Package $package = null) |
|
63 | |||
64 | /** |
||
65 | * Execute the console command. |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function fire() |
||
70 | { |
||
71 | // Data |
||
72 | $this->packageName = $this->askForArgument('package', 'What is your package name?'); |
||
|
|||
73 | $this->packageDescription = $this->askForArgument('description', 'What is your package description?'); |
||
74 | $this->licenceName = $this->chooseAnOption('Choose a licence', LicenceGenerator::showList()); |
||
75 | |||
76 | $this->package->setPackageName($this->packageName); |
||
77 | |||
78 | $this->manager->fire('package.new', $this->package); |
||
79 | |||
80 | // Base |
||
81 | // $this->package->setPackageName($this->packageName); |
||
82 | // $this->parser = new PackageParser($this->packageName); |
||
83 | // $generator = new PackageGenerator(); |
||
84 | |||
85 | // Composer |
||
86 | // $composer = $this->prepareComposer(); |
||
87 | // $generator->addGenerator($composer); |
||
88 | |||
89 | // Licence |
||
90 | // $licence = $this->prepareLicence(); |
||
91 | // $generator->addGenerator($licence); |
||
92 | |||
93 | // Readme |
||
94 | // $readme = $this->prepareReadme(); |
||
95 | // $generator->addGenerator($readme); |
||
96 | |||
97 | // Create the Package |
||
98 | // $generator->create($this->package); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get the console command arguments. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | 3 | protected function getArguments() |
|
113 | /** |
||
114 | * Get the console command options. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | 3 | protected function getOptions() |
|
126 | |||
127 | /** |
||
128 | * @return ComposerGenerator |
||
129 | */ |
||
130 | protected function prepareComposer() |
||
131 | { |
||
132 | $composer = new ComposerGenerator; |
||
133 | $composer->setData([ |
||
134 | 'name' => $this->parser->toPackageName(), |
||
135 | 'description' => $this->packageDescription, |
||
136 | 'psr4' => $this->parser->toPsr4(), // allow overriding this. |
||
137 | 'author' => $this->option('name'), // this will be a default setting and overridden by this flag. |
||
138 | 'email' => $this->option('email'), // this will be a default setting and overridden by this flag. |
||
139 | 'licence' => $this->licenceName |
||
140 | ]); |
||
141 | return $composer; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @return ReadmeGenerator |
||
146 | */ |
||
147 | protected function prepareReadme() |
||
148 | { |
||
149 | $readme = new ReadmeGenerator; |
||
150 | $readme->setData([ |
||
151 | 'name' => $this->parser->toHuman(), |
||
152 | 'description' => $this->packageDescription, |
||
153 | 'package' => $this->parser->toPackageName(), |
||
154 | 'licence' => LicenceGenerator::getLicenceName($this->licenceName) |
||
155 | ]); |
||
156 | return $readme; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return LicenceGenerator |
||
161 | */ |
||
162 | protected function prepareLicence() |
||
172 | } |
||
173 |
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.