Coding Standards

This commit is contained in:
Romain Neutron
2012-03-19 19:04:48 +01:00
parent f8ad7136cf
commit fa698fbdda
22 changed files with 56 additions and 41 deletions

View File

@@ -144,7 +144,7 @@ return call_user_func(function()
{ {
return; return;
} }
if ($oauth2_adapter->has_ses_id()) if ($oauth2_adapter->has_ses_id())
{ {
try try

View File

@@ -50,6 +50,6 @@ class ApcCache extends ServiceAbstract implements ServiceInterface
return 'apc'; return 'apc';
} }
} }

View File

@@ -36,7 +36,7 @@ class MemcacheCache extends ServiceAbstract implements ServiceInterface
protected function init() protected function init()
{ {
$options = $this->getOptions(); $options = $this->getOptions();
$this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST; $this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST;
$this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT; $this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT;

View File

@@ -25,7 +25,7 @@ use Alchemy\Phrasea\Core,
*/ */
class RedisCache extends ServiceAbstract implements ServiceInterface class RedisCache extends ServiceAbstract implements ServiceInterface
{ {
const DEFAULT_HOST = "localhost"; const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = "6379"; const DEFAULT_PORT = "6379";
@@ -36,7 +36,7 @@ class RedisCache extends ServiceAbstract implements ServiceInterface
protected function init() protected function init()
{ {
$options = $this->getOptions(); $options = $this->getOptions();
$this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST; $this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST;
$this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT; $this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT;

View File

@@ -37,7 +37,7 @@ class FirePHP extends ServiceAbstract implements ServiceInterface
$this->logger->pushHandler(new FirePHPHandler()); $this->logger->pushHandler(new FirePHPHandler());
} }
return $this->logger; return $this->logger;
} }

View File

@@ -40,7 +40,7 @@ class Monolog extends ServiceAbstract implements ServiceInterface
protected function init() protected function init()
{ {
$options = $this->getOptions(); $options = $this->getOptions();
if (empty($options)) if (empty($options))
{ {
throw new \Exception(sprintf("'%s' service options can not be empty", $this->name)); throw new \Exception(sprintf("'%s' service options can not be empty", $this->name));

View File

@@ -37,7 +37,7 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
protected function init() protected function init()
{ {
$options = $this->getOptions(); $options = $this->getOptions();
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
$this->debug = !!$options["debug"]; $this->debug = !!$options["debug"];

View File

@@ -25,7 +25,7 @@ interface ServiceInterface
public function getDriver(); public function getDriver();
public function getOptions(); public function getOptions();
public function getMandatoryOptions(); public function getMandatoryOptions();
} }

View File

@@ -578,7 +578,7 @@ class Edit extends RecordHelper
$collection = \collection::get_from_base_id($record->get_base_id()); $collection = \collection::get_from_base_id($record->get_base_id());
$collection->reset_stamp($record->get_record_id()); $collection->reset_stamp($record->get_record_id());
$record->write_metas(); $record->write_metas();
if ($statbits != '') if ($statbits != '')

View File

@@ -691,7 +691,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
continue; continue;
} }
} }
foreach ($base_ids as $base_id) foreach ($base_ids as $base_id)
{ {
if (!$ACL->has_access_to_base($base_id)) if (!$ACL->has_access_to_base($base_id))

View File

@@ -26,7 +26,7 @@ class Basket
const ELEMENTSORDER_NAT = 'nat'; const ELEMENTSORDER_NAT = 'nat';
const ELEMENTSORDER_DESC = 'desc'; const ELEMENTSORDER_DESC = 'desc';
const ELEMENTSORDER_ASC = 'asc'; const ELEMENTSORDER_ASC = 'asc';
/** /**
* @var integer $id * @var integer $id
*/ */
@@ -246,46 +246,46 @@ class Basket
{ {
return $this->elements; return $this->elements;
} }
public function getElementsByOrder($ordre) public function getElementsByOrder($ordre)
{ {
if($ordre === self::ELEMENTSORDER_DESC) if($ordre === self::ELEMENTSORDER_DESC)
{ {
$ret = new \Doctrine\Common\Collections\ArrayCollection(); $ret = new \Doctrine\Common\Collections\ArrayCollection();
$elements = $this->elements->toArray(); $elements = $this->elements->toArray();
uasort($elements, 'self::setBEOrderDESC'); uasort($elements, 'self::setBEOrderDESC');
foreach($elements as $elem) foreach($elements as $elem)
{ {
$ret->add($elem); $ret->add($elem);
} }
return $ret; return $ret;
} }
elseif($ordre === self::ELEMENTSORDER_ASC) elseif($ordre === self::ELEMENTSORDER_ASC)
{ {
$ret = new \Doctrine\Common\Collections\ArrayCollection(); $ret = new \Doctrine\Common\Collections\ArrayCollection();
$elements = $this->elements->toArray(); $elements = $this->elements->toArray();
uasort($elements, 'self::setBEOrderASC'); uasort($elements, 'self::setBEOrderASC');
foreach($elements as $elem) foreach($elements as $elem)
{ {
$ret->add($elem); $ret->add($elem);
} }
return $ret; return $ret;
} }
return $this->elements; return $this->elements;
} }
private static function setBEOrderDESC($element1, $element2) private static function setBEOrderDESC($element1, $element2)
{ {
$total_el1 = 0; $total_el1 = 0;
$total_el2 = 0; $total_el2 = 0;
foreach($element1->getValidationDatas() as $datas) foreach($element1->getValidationDatas() as $datas)
{ {
if($datas->getAgreement() !== null) if($datas->getAgreement() !== null)
@@ -300,18 +300,19 @@ class Basket
$total_el2 += $datas->getAgreement() ? 1 : 0; $total_el2 += $datas->getAgreement() ? 1 : 0;
} }
} }
if($total_el1 === $total_el2) if($total_el1 === $total_el2)
return 0; return 0;
return $total_el1 < $total_el2 ? 1 : -1; return $total_el1 < $total_el2 ? 1 : -1;
} }
private static function setBEOrderASC($element1, $element2) private static function setBEOrderASC($element1, $element2)
{ {
$total_el1 = 0; $total_el1 = 0;
$total_el2 = 0; $total_el2 = 0;
foreach($element1->getValidationDatas() as $datas) foreach($element1->getValidationDatas() as $datas)
{ {
if($datas->getAgreement() !== null) if($datas->getAgreement() !== null)
@@ -326,10 +327,11 @@ class Basket
$total_el2 += $datas->getAgreement() ? 0 : 1; $total_el2 += $datas->getAgreement() ? 0 : 1;
} }
} }
if($total_el1 === $total_el2) if($total_el1 === $total_el2)
return 0; return 0;
return $total_el1 < $total_el2 ? 1 : -1; return $total_el1 < $total_el2 ? 1 : -1;
} }

View File

@@ -411,6 +411,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa
public function get_content() public function get_content()
{ {
if ($this->items) if ($this->items)
return $this->items; return $this->items;
$rs = $this->retrieve_elements(); $rs = $this->retrieve_elements();

View File

@@ -582,6 +582,7 @@ class User_Query implements User_QueryInterface
public function get_total() public function get_total()
{ {
if ($this->total) if ($this->total)
return $this->total; return $this->total;
$conn = $this->appbox->get_connection(); $conn = $this->appbox->get_connection();
@@ -742,6 +743,7 @@ class User_Query implements User_QueryInterface
public function on_base_ids(Array $base_ids = null) public function on_base_ids(Array $base_ids = null)
{ {
if (!$base_ids) if (!$base_ids)
return $this; return $this;
$this->bases_restrictions = true; $this->bases_restrictions = true;
@@ -766,6 +768,7 @@ class User_Query implements User_QueryInterface
public function on_sbas_ids(Array $sbas_ids = null) public function on_sbas_ids(Array $sbas_ids = null)
{ {
if (!$sbas_ids) if (!$sbas_ids)
return $this; return $this;
$this->sbas_restrictions = true; $this->sbas_restrictions = true;

View File

@@ -79,6 +79,7 @@ class gatekeeper
$session = $appbox->get_session(); $session = $appbox->get_session();
if (http_request::is_command_line()) if (http_request::is_command_line())
return; return;
if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF'])) if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF']))
@@ -140,6 +141,7 @@ class gatekeeper
break; break;
case 'admin': case 'admin':
if ($this->_script_name === 'runscheduler.php') if ($this->_script_name === 'runscheduler.php')
return; return;
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']); phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
break; break;
@@ -159,6 +161,7 @@ class gatekeeper
return; return;
case 'setup': case 'setup':
if ($appbox->upgradeavailable()) if ($appbox->upgradeavailable())
return; return;
else else
phrasea::redirect('/login/'); phrasea::redirect('/login/');
@@ -275,6 +278,7 @@ class gatekeeper
$parm = $request->get_parms('LOG'); $parm = $request->get_parms('LOG');
if (is_null($parm["LOG"])) if (is_null($parm["LOG"]))
return $this; return $this;
try try

View File

@@ -245,4 +245,4 @@ class module_console_checkExtension extends Command
return 0; return 0;
} }
} }

View File

@@ -82,6 +82,7 @@ class module_console_fieldsDelete extends Command
if($continue != 'y') if($continue != 'y')
{ {
$output->writeln("Request canceled by user"); $output->writeln("Request canceled by user");
return 1; return 1;
} }

View File

@@ -89,6 +89,7 @@ class module_console_fieldsRename extends Command
if($continue != 'y') if($continue != 'y')
{ {
$output->writeln("Request canceled by user"); $output->writeln("Request canceled by user");
return 1; return 1;
} }

View File

@@ -60,19 +60,21 @@ class module_console_sphinxGenerateSuggestion extends Command
$databox = databox::get_instance($sbas_id); $databox = databox::get_instance($sbas_id);
$output->writeln("process Databox " . $databox->get_viewname() . " / $index\n"); $output->writeln("process Databox " . $databox->get_viewname() . " / $index\n");
if(!is_executable("/usr/local/bin/indexer")) if(!is_executable("/usr/local/bin/indexer"))
{ {
$output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>"); $output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>");
return 1; return 1;
} }
if(!file_exists($tmp_file)) if(!file_exists($tmp_file))
{ {
$output->writeln("<error> file '".$tmp_file."' does not exist</error>"); $output->writeln("<error> file '".$tmp_file."' does not exist</error>");
return 1; return 1;
} }
$cmd = '/usr/local/bin/indexer metadatas' . $index . ' --buildstops ' . $tmp_file . ' 1000000 --buildfreqs'; $cmd = '/usr/local/bin/indexer metadatas' . $index . ' --buildstops ' . $tmp_file . ' 1000000 --buildfreqs';
exec($cmd); exec($cmd);

View File

@@ -1406,7 +1406,7 @@ class unicode
{ {
$regexp .= '\.'; $regexp .= '\.';
} }
$regexp .= ']{1}/'; $regexp .= ']{1}/';
$string = $this->remove_diacritics($string); $string = $this->remove_diacritics($string);

View File

@@ -303,13 +303,13 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition")); $this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition"));
} }
public function testResetRights() public function testResetRights()
{ {
$appbox = \appbox::get_instance(self::$core); $appbox = \appbox::get_instance(self::$core);
$username = uniqid('user_'); $username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false); $user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes())); $user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes()));
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox)
@@ -340,8 +340,8 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
break; break;
} }
} }
// //
$this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id())); $this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id()));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOK()); $this->assertTrue($response->isOK());

View File

@@ -152,7 +152,7 @@
<option value="{{ template.get_id() }}">{{ template.get_display_name() }}</option> <option value="{{ template.get_id() }}">{{ template.get_display_name() }}</option>
{% endfor %} {% endfor %}
</select> </select>
<button type='button' id='reset_rights'>{% trans 'reset users rights' %}</button> <button type='button' id='reset_rights'>{% trans 'reset users rights' %}</button>
</td> </td>
</tr> </tr>
</table> </table>
@@ -579,7 +579,7 @@ $('#users_rights_form button#reset_rights').bind('click', function(){
if(confirm("{% trans'are you sure you want reset rights ?' %}")) if(confirm("{% trans'are you sure you want reset rights ?' %}"))
{ {
var users = $('#users_rights_form input[name="users"]').val(); var users = $('#users_rights_form input[name="users"]').val();
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/admin/users/rights/reset/', url: '/admin/users/rights/reset/',
@@ -608,6 +608,7 @@ $('#users_rights_form button#reset_rights').bind('click', function(){
$('#right-ajax').removeClass('loading').html(data); $('#right-ajax').removeClass('loading').html(data);
} }
}); });
return false; return false;
} }
else else
@@ -618,5 +619,5 @@ $('#users_rights_form button#reset_rights').bind('click', function(){
}); });
} }
}); });
</script> </script>

View File

@@ -312,7 +312,7 @@
</select> </select>
</form> </form>
</div> </div>
{% for basket_element in basket.getElementsByOrder(ordre) %} {% for basket_element in basket.getElementsByOrder(ordre) %}
<span class="wrapCHIM_{{ basket_element.getRecord().get_serialize_key() }} valid"> <span class="wrapCHIM_{{ basket_element.getRecord().get_serialize_key() }} valid">
<table style="width: 100%; min-width: 330px; display: inline-block;"> <table style="width: 100%; min-width: 330px; display: inline-block;">