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;
}
if ($oauth2_adapter->has_ses_id())
{
try

View File

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

View File

@@ -36,7 +36,7 @@ class MemcacheCache extends ServiceAbstract implements ServiceInterface
protected function init()
{
$options = $this->getOptions();
$this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST;
$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
{
const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = "6379";
@@ -36,7 +36,7 @@ class RedisCache extends ServiceAbstract implements ServiceInterface
protected function init()
{
$options = $this->getOptions();
$this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST;
$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());
}
return $this->logger;
}

View File

@@ -40,7 +40,7 @@ class Monolog extends ServiceAbstract implements ServiceInterface
protected function init()
{
$options = $this->getOptions();
if (empty($options))
{
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()
{
$options = $this->getOptions();
$config = new \Doctrine\ORM\Configuration();
$this->debug = !!$options["debug"];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1406,7 +1406,7 @@ class unicode
{
$regexp .= '\.';
}
$regexp .= ']{1}/';
$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"));
}
public function testResetRights()
{
$appbox = \appbox::get_instance(self::$core);
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes()));
foreach ($appbox->get_databoxes() as $databox)
@@ -340,8 +340,8 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
break;
}
}
//
//
$this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());

View File

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

View File

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