Skip to content

Commit

Permalink
remove chains
Browse files Browse the repository at this point in the history
  • Loading branch information
zalevsk1y committed Sep 13, 2019
1 parent c12f2db commit 182092f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 193 deletions.
125 changes: 45 additions & 80 deletions Coverage.clover
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1568385628">
<project timestamp="1568385628">
<coverage generated="1568386620">
<project timestamp="1568386620">
<package name="ContributorsPlugin\Controllers">
<file name="/var/www/html/wpblog1/wp-content/plugins/contributors/inc/Controllers/MetaboxController.php">
<class name="ContributorsPlugin\Controllers\MetaboxController" namespace="ContributorsPlugin\Controllers">
<metrics complexity="26" methods="10" coveredmethods="6" conditionals="0" coveredconditionals="0" statements="70" coveredstatements="64" elements="80" coveredelements="70"/>
<metrics complexity="25" methods="9" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="66" coveredstatements="61" elements="75" coveredelements="66"/>
</class>
<line num="31" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="4"/>
<line num="33" type="stmt" count="4"/>
Expand All @@ -16,107 +16,72 @@
<line num="45" type="stmt" count="4"/>
<line num="46" type="stmt" count="4"/>
<line num="47" type="stmt" count="4"/>
<line num="54" type="method" name="saveMetaData" visibility="public" complexity="5" crap="5.15" count="4"/>
<line num="54" type="method" name="saveMetaData" visibility="public" complexity="6" crap="6.05" count="4"/>
<line num="56" type="stmt" count="4"/>
<line num="57" type="stmt" count="4"/>
<line num="58" type="stmt" count="4"/>
<line num="59" type="stmt" count="4"/>
<line num="60" type="stmt" count="0"/>
<line num="62" type="stmt" count="4"/>
<line num="60" type="stmt" count="4"/>
<line num="61" type="stmt" count="4"/>
<line num="63" type="stmt" count="4"/>
<line num="65" type="stmt" count="4"/>
<line num="66" type="stmt" count="4"/>
<line num="68" type="stmt" count="0"/>
<line num="71" type="stmt" count="4"/>
<line num="77" type="method" name="autosaveCheck" visibility="public" complexity="3" crap="3.33" count="4"/>
<line num="79" type="stmt" count="4"/>
<line num="80" type="stmt" count="0"/>
<line num="82" type="stmt" count="4"/>
<line num="90" type="method" name="havePermission" visibility="public" complexity="4" crap="4.25" count="4"/>
<line num="92" type="stmt" count="4"/>
<line num="93" type="stmt" count="4"/>
<line num="96" type="stmt" count="4"/>
<line num="97" type="stmt" count="4"/>
<line num="98" type="stmt" count="0"/>
<line num="101" type="stmt" count="4"/>
<line num="102" type="stmt" count="0"/>
<line num="105" type="stmt" count="4"/>
<line num="113" type="method" name="renderPostContributorsBox" visibility="public" complexity="2" crap="2" count="2"/>
<line num="64" type="stmt" count="4"/>
<line num="66" type="stmt" count="0"/>
<line num="69" type="stmt" count="4"/>
<line num="75" type="method" name="autosaveCheck" visibility="public" complexity="3" crap="3.33" count="4"/>
<line num="77" type="stmt" count="4"/>
<line num="78" type="stmt" count="0"/>
<line num="80" type="stmt" count="4"/>
<line num="88" type="method" name="havePermission" visibility="public" complexity="4" crap="4.25" count="4"/>
<line num="90" type="stmt" count="4"/>
<line num="91" type="stmt" count="4"/>
<line num="94" type="stmt" count="4"/>
<line num="95" type="stmt" count="4"/>
<line num="96" type="stmt" count="0"/>
<line num="99" type="stmt" count="4"/>
<line num="100" type="stmt" count="0"/>
<line num="103" type="stmt" count="4"/>
<line num="111" type="method" name="renderPostContributorsBox" visibility="public" complexity="2" crap="2" count="2"/>
<line num="113" type="stmt" count="2"/>
<line num="114" type="stmt" count="2"/>
<line num="115" type="stmt" count="2"/>
<line num="116" type="stmt" count="2"/>
<line num="117" type="stmt" count="2"/>
<line num="118" type="stmt" count="2"/>
<line num="119" type="stmt" count="2"/>
<line num="122" type="stmt" count="2"/>
<line num="123" type="stmt" count="2"/>
<line num="129" type="method" name="addContributorsBox" visibility="public" complexity="1" crap="1" count="1"/>
<line num="120" type="stmt" count="2"/>
<line num="121" type="stmt" count="2"/>
<line num="127" type="method" name="addContributorsBox" visibility="public" complexity="1" crap="1" count="1"/>
<line num="129" type="stmt" count="1"/>
<line num="130" type="stmt" count="1"/>
<line num="131" type="stmt" count="1"/>
<line num="132" type="stmt" count="1"/>
<line num="133" type="stmt" count="1"/>
<line num="134" type="stmt" count="1"/>
<line num="135" type="stmt" count="1"/>
<line num="136" type="stmt" count="1"/>
<line num="137" type="stmt" count="1"/>
<line num="139" type="stmt" count="1"/>
<line num="148" type="method" name="getContributorsData" visibility="protected" complexity="3" crap="3" count="2"/>
<line num="146" type="method" name="getContributorsData" visibility="protected" complexity="3" crap="3" count="2"/>
<line num="148" type="stmt" count="2"/>
<line num="149" type="stmt" count="2"/>
<line num="150" type="stmt" count="2"/>
<line num="151" type="stmt" count="2"/>
<line num="152" type="stmt" count="2"/>
<line num="153" type="stmt" count="2"/>
<line num="154" type="stmt" count="2"/>
<line num="155" type="stmt" count="2"/>
<line num="156" type="stmt" count="2"/>
<line num="160" type="stmt" count="2"/>
<line num="168" type="method" name="renderPost" visibility="public" complexity="4" crap="4.00" count="1"/>
<line num="170" type="stmt" count="1"/>
<line num="171" type="stmt" count="1"/>
<line num="172" type="stmt" count="0"/>
<line num="158" type="stmt" count="2"/>
<line num="166" type="method" name="renderPost" visibility="public" complexity="4" crap="4.00" count="1"/>
<line num="168" type="stmt" count="1"/>
<line num="169" type="stmt" count="1"/>
<line num="170" type="stmt" count="0"/>
<line num="172" type="stmt" count="1"/>
<line num="173" type="stmt" count="1"/>
<line num="174" type="stmt" count="1"/>
<line num="175" type="stmt" count="1"/>
<line num="176" type="stmt" count="1"/>
<line num="177" type="stmt" count="1"/>
<line num="178" type="stmt" count="1"/>
<line num="179" type="stmt" count="1"/>
<line num="180" type="stmt" count="1"/>
<line num="181" type="stmt" count="1"/>
<line num="182" type="stmt" count="1"/>
<line num="183" type="stmt" count="1"/>
<line num="184" type="stmt" count="1"/>
<line num="187" type="stmt" count="1"/>
<line num="188" type="stmt" count="1"/>
<line num="197" type="method" name="chain" visibility="protected" complexity="2" crap="2" count="4"/>
<line num="199" type="stmt" count="4"/>
<line num="200" type="stmt" count="4"/>
<metrics loc="202" ncloc="129" classes="1" methods="10" coveredmethods="6" conditionals="0" coveredconditionals="0" statements="70" coveredstatements="64" elements="80" coveredelements="70"/>
</file>
</package>
<package name="ContributorsPlugin\Exception">
<file name="/var/www/html/wpblog1/wp-content/plugins/contributors/inc/Exception/MyException.php">
<class name="ContributorsPlugin\Exception\MyException" namespace="ContributorsPlugin\Exception" fullPackage="Exception" package="Exception">
<metrics complexity="1" methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="3" coveredstatements="0" elements="4" coveredelements="0"/>
</class>
<line num="28" type="method" name="__construct" visibility="public" complexity="1" crap="2.00" count="0"/>
<line num="30" type="stmt" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<metrics loc="33" ncloc="12" classes="1" methods="1" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="3" coveredstatements="0" elements="4" coveredelements="0"/>
</file>
</package>
<package name="ContributorsPlugin\Utils">
<file name="/var/www/html/wpblog1/wp-content/plugins/contributors/inc/Utils/ChainController.php">
<class name="ContributorsPlugin\Utils\ChainController" namespace="ContributorsPlugin\Utils" fullPackage="Utils" package="Utils">
<metrics complexity="6" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="6" elements="10" coveredelements="7"/>
</class>
<line num="42" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="4"/>
<line num="44" type="stmt" count="4"/>
<line num="45" type="stmt" count="4"/>
<line num="47" type="method" name="__call" visibility="public" complexity="5" crap="5.93" count="4"/>
<line num="49" type="stmt" count="4"/>
<line num="50" type="stmt" count="0"/>
<line num="52" type="stmt" count="4"/>
<line num="53" type="stmt" count="4"/>
<line num="56" type="stmt" count="0"/>
<line num="58" type="stmt" count="4"/>
<metrics loc="60" ncloc="26" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="6" elements="10" coveredelements="7"/>
<line num="185" type="stmt" count="1"/>
<line num="186" type="stmt" count="1"/>
<metrics loc="188" ncloc="122" classes="1" methods="9" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="66" coveredstatements="61" elements="75" coveredelements="66"/>
</file>
</package>
<package name="ContributorsPlugin\View">
Expand Down Expand Up @@ -145,6 +110,6 @@
<metrics loc="67" ncloc="36" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="16" coveredstatements="14" elements="18" coveredelements="15"/>
</file>
</package>
<metrics files="4" loc="362" ncloc="203" classes="4" methods="15" coveredmethods="8" conditionals="0" coveredconditionals="0" statements="97" coveredstatements="84" elements="112" coveredelements="92"/>
<metrics files="2" loc="255" ncloc="158" classes="2" methods="11" coveredmethods="6" conditionals="0" coveredconditionals="0" statements="82" coveredstatements="75" elements="93" coveredelements="81"/>
</project>
</coverage>
26 changes: 6 additions & 20 deletions inc/Controllers/MetaboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use ContributorsPlugin\Exception\MyException;
use ContributorsPlugin\View\TemplateRender;
use ContributorsPlugin\Utils\ChainController;

/**
* Class manage metabox functions.
*
Expand Down Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
33 changes: 0 additions & 33 deletions inc/Exception/MyException.php

This file was deleted.

60 changes: 0 additions & 60 deletions inc/Utils/ChainController.php

This file was deleted.

0 comments on commit 182092f

Please sign in to comment.