Skip to content

Commit 5fb6515

Browse files
hjuarez20enzolutions
authored andcommitted
[core] Fix WPStyle and update getConfigGlobalAsArray function (#39)
1 parent 247c947 commit 5fb6515

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

src/Core/Command/Settings/SetCommand.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Component\Yaml\Dumper;
1414
use Symfony\Component\Yaml\Parser;
1515
use WP\Console\Core\Command\Command;
16+
use WP\Console\Core\Style\WPStyle;
1617
use WP\Console\Core\Utils\ConfigurationManager;
1718
use WP\Console\Core\Utils\NestedArray;
1819

@@ -76,6 +77,8 @@ protected function configure()
7677
*/
7778
protected function execute(InputInterface $input, OutputInterface $output)
7879
{
80+
$io = new WPStyle($input, $output);
81+
7982
$parser = new Parser();
8083
$dumper = new Dumper();
8184

@@ -93,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9396
);
9497

9598
if (!file_exists($userConfigFile)) {
96-
$this->getIo()->error(
99+
$io->error(
97100
sprintf(
98101
$this->trans('commands.settings.set.messages.missing-file'),
99102
$userConfigFile
@@ -107,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
107110
file_get_contents($userConfigFile)
108111
);
109112
} catch (\Exception $e) {
110-
$this->getIo()->error(
113+
$io->error(
111114
$this->trans(
112115
'commands.settings.set.messages.error-parsing'
113116
) . ': ' . $e->getMessage()
@@ -127,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
127130
try {
128131
$userConfigFileDump = $dumper->dump($userConfigFileParsed, 10);
129132
} catch (\Exception $e) {
130-
$this->getIo()->error(
133+
$io->error(
131134
[
132135
$this->trans('commands.settings.set.messages.error-generating'),
133136
$e->getMessage()
@@ -144,7 +147,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144147

145148
$translatorLanguage = $this->getApplication()->getTranslator()->getLanguage();
146149
if ($translatorLanguage != $settingValue) {
147-
$this->getIo()->error(
150+
$io->error(
148151
sprintf(
149152
$this->trans('commands.settings.set.messages.missing-language'),
150153
$settingValue
@@ -158,7 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
158161
try {
159162
file_put_contents($userConfigFile, $userConfigFileDump);
160163
} catch (\Exception $e) {
161-
$this->getIo()->error(
164+
$io->error(
162165
[
163166
$this->trans('commands.settings.set.messages.error-writing'),
164167
$e->getMessage()
@@ -167,5 +170,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
167170

168171
return 1;
169172
}
173+
174+
$io->success(
175+
sprintf(
176+
$this->trans('commands.settings.set.messages.success'),
177+
$settingName,
178+
$settingValue
179+
)
180+
);
181+
182+
return 0;
170183
}
171184
}

src/Core/EventSubscriber/CalculateStatisticsListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function calculateStatistics(ConsoleTerminateEvent $event)
5959
return;
6060
}
6161

62-
$globalConfig = $this->configurationManager->getConfigAsArray();
62+
$configGlobalAsArray = $this->configurationManager->getConfigGlobalAsArray();
6363

6464
//Validate if the config is enable.
65-
if (is_null($globalConfig) || !$globalConfig['application']['share']['statistics']) {
65+
if (is_null($configGlobalAsArray) || !$configGlobalAsArray['application']['share']['statistics']) {
6666
return;
6767
}
6868

src/Core/EventSubscriber/SaveStatisticsListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class SaveStatisticsListener implements EventSubscriberInterface
4747
/**
4848
* SaveStatisticsListener constructor.
4949
*
50-
* @param CountCodeLines $countCodeLines
51-
* @param ConfigurationManager $configurationManager
52-
* @param TranslatorManager $translator
50+
* @param CountCodeLines $countCodeLines
51+
* @param ConfigurationManager $configurationManager
52+
* @param TranslatorManager $translator
5353
*/
5454
public function __construct(
5555
CountCodeLines $countCodeLines,
@@ -72,10 +72,10 @@ public function saveStatistics(ConsoleTerminateEvent $event)
7272
return;
7373
}
7474

75-
$globalConfig = $this->configurationManager->getConfigAsArray();
75+
$configGlobalAsArray = $this->configurationManager->getConfigGlobalAsArray();
7676

7777
//Validate if the config is enable.
78-
if (is_null($globalConfig) || !$globalConfig['application']['share']['statistics']) {
78+
if (is_null($configGlobalAsArray) || !$configGlobalAsArray['application']['share']['statistics']) {
7979
return;
8080
}
8181

src/Core/Generator/InitGenerator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace WP\Console\Core\Generator;
88

9+
use WP\Console\Core\Style\WPStyle;
910
use WP\Console\Core\Utils\NestedArray;
1011
use Symfony\Component\Yaml\Dumper;
1112
use Symfony\Component\Yaml\Parser;
@@ -116,12 +117,6 @@ private function resetStatisticsConfig($homeDirectory, $statisticsValue)
116117
$userConfigFile = $homeDirectory . 'config.yml';
117118

118119
if (!file_exists($userConfigFile)) {
119-
$this->getIo()->error(
120-
sprintf(
121-
$this->trans('commands.settings.set.messages.missing-file'),
122-
$userConfigFile
123-
)
124-
);
125120
return 1;
126121
}
127122

src/Core/Utils/ConfigurationManager.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ public function loadExtendConfiguration()
256256
}
257257

258258
/**
259-
* Get the config as array.
259+
* Get config global as array.
260260
*
261261
* @return array
262262
*/
263-
public function getConfigAsArray()
263+
public function getConfigGlobalAsArray()
264264
{
265265
$filePath = sprintf(
266266
'%s/.wp-console/config.yml',
@@ -269,13 +269,13 @@ public function getConfigAsArray()
269269

270270
$fs = new Filesystem();
271271

272-
if ($fs->exists($filePath)) {
273-
$yaml = new Parser();
274-
$configGlobal = $yaml->parse(file_get_contents($filePath), true);
275-
276-
return $configGlobal;
272+
if (!$fs->exists($filePath)) {
273+
return null;
277274
}
278275

279-
return null;
276+
$yaml = new Parser();
277+
$configGlobal = $yaml->parse(file_get_contents($filePath), true);
278+
279+
return $configGlobal;
280280
}
281281
}

0 commit comments

Comments
 (0)