diff --git a/src/N98/Magento/Command/System/Check/ResultCollection.php b/src/N98/Magento/Command/System/Check/ResultCollection.php
index 410e3a216..65b5817d9 100644
--- a/src/N98/Magento/Command/System/Check/ResultCollection.php
+++ b/src/N98/Magento/Command/System/Check/ResultCollection.php
@@ -2,6 +2,13 @@
namespace N98\Magento\Command\System\Check;
+use Traversable;
+
+/**
+ * Class ResultCollection
+ *
+ * @package N98\Magento\Command\System\Check
+ */
class ResultCollection implements \IteratorAggregate
{
/**
diff --git a/src/N98/Magento/Command/System/Check/SimpleCheck.php b/src/N98/Magento/Command/System/Check/SimpleCheck.php
index 289df1986..22d3df7b1 100644
--- a/src/N98/Magento/Command/System/Check/SimpleCheck.php
+++ b/src/N98/Magento/Command/System/Check/SimpleCheck.php
@@ -2,6 +2,11 @@
namespace N98\Magento\Command\System\Check;
+/**
+ * Interface SimpleCheck
+ *
+ * @package N98\Magento\Command\System\Check
+ */
interface SimpleCheck
{
/**
diff --git a/src/N98/Magento/Command/System/Check/StoreCheck.php b/src/N98/Magento/Command/System/Check/StoreCheck.php
index c45e6b975..e214c4011 100644
--- a/src/N98/Magento/Command/System/Check/StoreCheck.php
+++ b/src/N98/Magento/Command/System/Check/StoreCheck.php
@@ -2,10 +2,18 @@
namespace N98\Magento\Command\System\Check;
+/**
+ * Interface StoreCheck
+ *
+ * @package N98\Magento\Command\System\Check
+ */
interface StoreCheck
{
/**
- * @param ResultCollection $results
+ * @param ResultCollection $results
+ * @param \Mage_Core_Model_Store $store
+ *
+ * @return
*/
public function check(ResultCollection $results, \Mage_Core_Model_Store $store);
}
diff --git a/src/N98/Magento/Command/System/Check/WebsiteCheck.php b/src/N98/Magento/Command/System/Check/WebsiteCheck.php
index 4f2ca97dd..be04fa215 100644
--- a/src/N98/Magento/Command/System/Check/WebsiteCheck.php
+++ b/src/N98/Magento/Command/System/Check/WebsiteCheck.php
@@ -2,10 +2,18 @@
namespace N98\Magento\Command\System\Check;
+/**
+ * Interface WebsiteCheck
+ *
+ * @package N98\Magento\Command\System\Check
+ */
interface WebsiteCheck
{
/**
- * @param ResultCollection $results
+ * @param ResultCollection $results
+ * @param \Mage_Core_Model_Website $website
+ *
+ * @return
*/
public function check(ResultCollection $results, \Mage_Core_Model_Website $website);
}
diff --git a/src/N98/Magento/Command/System/CheckCommand.php b/src/N98/Magento/Command/System/CheckCommand.php
index b3eeca5bf..37fd0c53a 100644
--- a/src/N98/Magento/Command/System/CheckCommand.php
+++ b/src/N98/Magento/Command/System/CheckCommand.php
@@ -13,6 +13,11 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+/**
+ * Class CheckCommand
+ *
+ * @package N98\Magento\Command\System
+ */
class CheckCommand extends AbstractMagentoCommand
{
const UNICODE_CHECKMARK_CHAR = 10004;
@@ -76,35 +81,45 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @param ResultCollection $results
- * @param mixed $checkGroupClass
- * @internal param ResultCollection $resultCollection
+ * @param string $checkGroupClass name
*/
protected function _invokeCheckClass(ResultCollection $results, $checkGroupClass)
{
- $check = new $checkGroupClass();
- if ($check instanceof CommandAware) {
- $check->setCommand($this);
- }
- if ($check instanceof CommandConfigAware) {
- $check->setCommandConfig($this->_config);
- }
+ $check = $this->_createCheck($checkGroupClass);
- if ($check instanceof Check\SimpleCheck) {
- $check->check($results);
- } elseif ($check instanceof Check\StoreCheck) {
- foreach (\Mage::app()->getStores() as $store) {
- $check->check($results, $store);
- }
- } elseif ($check instanceof Check\WebsiteCheck) {
- foreach (\Mage::app()->getWebsites() as $website) {
- $check->check($results, $website);
- }
+ switch (true) {
+ case $check instanceof Check\SimpleCheck:
+ $check->check($results);
+ break;
+
+ case $check instanceof Check\StoreCheck:
+ if (!$stores = \Mage::app()->getStores()) {
+ $this->_markCheckWarning($results, 'stores', $checkGroupClass);
+ }
+ foreach ($stores as $store) {
+ $check->check($results, $store);
+ }
+ break;
+
+ case $check instanceof Check\WebsiteCheck:
+ if (!$websites = \Mage::app()->getWebsites()) {
+ $this->_markCheckWarning($results, 'websites', $checkGroupClass);
+ }
+ foreach ($websites as $website) {
+ $check->check($results, $website);
+ }
+ break;
+
+ default:
+ throw new \LogicException(
+ sprintf('Unhandled check-class "%s"', $checkGroupClass)
+ );
}
}
/**
- * @param OutputInterface $output
- * @param Result $result
+ * @param OutputInterface $output
+ * @param ResultCollection $results
*/
protected function _printResults(OutputInterface $output, ResultCollection $results)
{
@@ -120,8 +135,8 @@ protected function _printResults(OutputInterface $output, ResultCollection $resu
$output->write('' . \N98\Util\Unicode\Charset::convertInteger(Charset::UNICODE_CROSS_CHAR) . ' ');
break;
- default:
case Result::STATUS_OK:
+ default:
$output->write('' . \N98\Util\Unicode\Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR) . ' ');
break;
}
@@ -133,9 +148,9 @@ protected function _printResults(OutputInterface $output, ResultCollection $resu
}
/**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @param Result $result
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @param ResultCollection $results
*/
protected function _printTable(InputInterface $input, OutputInterface $output, ResultCollection $results)
{
@@ -153,4 +168,38 @@ protected function _printTable(InputInterface $input, OutputInterface $output, R
->setHeaders(array('Group', 'Message', 'Result'))
->renderByFormat($output, $table, $input->getOption('format'));
}
+
+ /**
+ * @param string $checkGroupClass
+ *
+ * @return object
+ */
+ private function _createCheck($checkGroupClass)
+ {
+ $check = new $checkGroupClass();
+
+ if ($check instanceof CommandAware) {
+ $check->setCommand($this);
+ }
+ if ($check instanceof CommandConfigAware) {
+ $check->setCommandConfig($this->_config);
+
+ return $check;
+ }
+
+ return $check;
+ }
+
+ /**
+ * @param ResultCollection $results
+ * @param string $context
+ * @param string $checkGroupClass
+ */
+ private function _markCheckWarning(ResultCollection $results, $context, $checkGroupClass)
+ {
+ $result = $results->createResult();
+ $result->setMessage('No ' . $context . ' configured to run store check: ' . basename($checkGroupClass) . '');
+ $result->setStatus($result::STATUS_WARNING);
+ $results->addResult($result);
+ }
}