diff --git a/Coverage.clover b/Coverage.clover index 3caad45..f357bdf 100644 --- a/Coverage.clover +++ b/Coverage.clover @@ -1,10 +1,10 @@ - - + + - + @@ -16,107 +16,72 @@ - + - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - + + + - - - - - - - + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -145,6 +110,6 @@ - + diff --git a/inc/Controllers/MetaboxController.php b/inc/Controllers/MetaboxController.php index 3778a10..f607cb4 100644 --- a/inc/Controllers/MetaboxController.php +++ b/inc/Controllers/MetaboxController.php @@ -3,7 +3,7 @@ use ContributorsPlugin\Exception\MyException; use ContributorsPlugin\View\TemplateRender; -use ContributorsPlugin\Utils\ChainController; + /** * Class manage metabox functions. * @@ -53,11 +53,9 @@ public function addActions() */ public function saveMetaData($post_id) { - $result_of_check=$this->chain($this) - ->autosaveCheck() - ->havePermission($post_id); - if(is_wp_error($result_of_check)){ - return $result_of_check->get_error_message(); + $result_of_permission_check=$this->havePermission($post_id); + if($this->autosaveCheck()||is_wp_error($result_of_permission_check)){ + return ; } if (isset($_POST[CONTRIBUTORS_PLUGIN_FIELD])) { $contributors = sanitize_meta(CONTRIBUTORS_PLUGIN_META, $_POST[CONTRIBUTORS_PLUGIN_FIELD], 'post'); @@ -72,12 +70,12 @@ public function saveMetaData($post_id) /** * Check is save action is autosave * - * @return object $this for chain building + * @return bool */ public function autosaveCheck() { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { - return new \WP_Error(__('Doing autosave.',CONTRIBUTORS_PLUGIN_SLUG)); + return true; } return false; } @@ -187,16 +185,4 @@ public function renderPost($content) $contributors_box = $this->postTemplate->render(array('contributors' => $user_data)); return $content . $contributors_box; } - /** - * Facade for chain building class. use NewsParserPlugin\::get() function at the end to get result. - * - * @param object|null object which methods will be called in chain. - * - * @return object ChainController - */ - protected function chain($object=null) - { - $object=is_null($object)?$this:$object; - return new ChainController($object); - } } diff --git a/inc/Exception/MyException.php b/inc/Exception/MyException.php deleted file mode 100755 index d8f629b..0000000 --- a/inc/Exception/MyException.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @license MIT - * - */ -class MyException extends \Exception -{ - /** - * Original Exception instance. - * - * @var \Exception - */ - protected $original; - /** - * Init function. - * - * @param string $msg error message - * @param \Exception $e Original Exception instance. - */ - public function __construct($msg, $e = null) - { - $this->original = $e; - parent::__construct($msg); - } -} diff --git a/inc/Utils/ChainController.php b/inc/Utils/ChainController.php deleted file mode 100755 index 3fa19b1..0000000 --- a/inc/Utils/ChainController.php +++ /dev/null @@ -1,60 +0,0 @@ -myMethod1($arg) - * ->myMethod2($arg) - * ->myMethod3($arg) - * ->get() - * - * - * - * - * @package Utils - * @author Evgeniy S.Zalevskiy <2600@ukr.net> - * @license MIT - */ -class ChainController -{ - /** - * Object whose methods was included in chain. - * - * @var object - */ - protected $context; - /** - * Result of execution chained methods. - * - * @var mixed - */ - protected $result; - /** - * You could add to chain only methods of one class, but not the functions - * - * @param object instance of object whose methods you will add to the chain. - */ - public function __construct($object) - { - $this->context = $object; - } - - public function __call($method, $args) - { - if ($method == 'get') { - return $this->result ?: false; - } - if (method_exists($this->context, $method)) { - $this->result = $this->result ?: call_user_func_array(array($this->context, $method), $args); - - } else { - throw new \Exception('Wrong method name ' . get_class($this->context) . '::' . $method); - } - return $this; - } -}