Coding Standards

This commit is contained in:
Romain Neutron
2012-02-13 18:23:06 +01:00
parent bc9470290b
commit 8a154e21c1
40 changed files with 99 additions and 63 deletions

View File

@@ -76,7 +76,7 @@ class Subdefs implements ControllerProviderInterface
{
$subdefs = $databox->get_subdef_structure();
$UnicodeProcessor = new \unicode();
$group = $add_subdef['group'];
$name = $UnicodeProcessor->remove_nonazAZ09($add_subdef['name'], false);
$class = $add_subdef['class'];

View File

@@ -66,4 +66,4 @@ class UserPreferences implements ControllerProviderInterface
return $controllers;
}
}
}

View File

@@ -242,7 +242,7 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
, realpath(__DIR__ . '/../../../../../Doctrine')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Events'
, realpath(__DIR__ . '/../../../../../Doctrine')

View File

@@ -511,7 +511,7 @@ class Edit extends RecordHelper
{
return $this;
}
$sbas_id = (int) $request->get('sbid');
$databox = \databox::get_instance($sbas_id);
$meta_struct = $databox->get_meta_structure();

View File

@@ -25,13 +25,13 @@ class Autoloader extends UniversalClassLoader
{
/**
* An array of path to check
* @var type
* @var type
*/
private $paths = array();
/**
* Construct a new phrasea Autoloader
* Because some custom classes from library folder might be
* Because some custom classes from library folder might be
* overwritten in config folder
* Phraseanet Loader look classes in configuration folders first
* then check library folder if no classes where matched
@@ -41,7 +41,7 @@ class Autoloader extends UniversalClassLoader
$this->paths['config'] = __DIR__ . '/../../../../config/classes/';
$this->paths['library'] = __DIR__ . '/../../../classes/';
}
/**
* {@inheritdoc}
*/
@@ -58,35 +58,35 @@ class Autoloader extends UniversalClassLoader
/**
* Add a path to look for autoloading phraseanet classes
* @param string $name
* @param string $path
* @param string $path
*/
public function addPath($name, $path)
{
$this->paths[$name] = \p4string::addEndSlash($path);
}
/**
* Check whether a class with $class name exists
* foreach declared paths
* @param string $class
* @return mixed string|null
* @return mixed string|null
*/
private function checkFile($class)
{
foreach($this->paths as $path)
{
$file = $path. str_replace('_', '/', $class) . '.class.php';
if(file_exists($file))
{
return $file;
}
}
}
/**
* Get Paths where classes are checked for autoloading
* @return Array
* @return Array
*/
public function getPaths()
{

View File

@@ -75,12 +75,12 @@ class CacheAutoloader extends Autoloader
}
$method = new $className();
if($namespace)
{
$method->setNamespace($namespace);
}
if ($method instanceof LoaderStrategy && $method->isAvailable())
{
$this->cacheAdapter = $method;

View File

@@ -22,7 +22,7 @@ interface LoaderStrategy
/**
* Check wether the cacheAdapter is available
* @Return boolean
* @Return boolean
*/
public function isAvailable();

View File

@@ -56,6 +56,7 @@ class StoryWZRepository extends EntityRepository
{
return 0;
}
return ($a->getRecord()->get_title() < $b->getRecord()->get_title()) ? -1 : 1;
}

View File

@@ -336,11 +336,11 @@ class ACL implements cache_cacheableInterface
$mask_and = $template_user->ACL()->get_mask_and($base_id);
$mask_xor = $template_user->ACL()->get_mask_xor($base_id);
$mask_and = ctype_digit($mask_and) ? $mask_and : '0';
$mask_xor = ctype_digit($mask_xor) ? $mask_xor : '0';
/**
* apply sb is substractive
*/

View File

@@ -1112,6 +1112,7 @@ class API_V1_adapter extends API_V1_Abstract
* @todo ajouter une option pour avoir les values serialisées
* dans un cas multi
*/
return array(
'meta_id' => $value->getId()
, 'meta_structure_id' => $field->get_meta_struct_id()

View File

@@ -1490,7 +1490,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{
return $this->_prefs[$prop];
}
$ok = true;
if (isset(self::$available_values[$prop]))

View File

@@ -180,12 +180,12 @@ abstract class base implements cache_cacheableInterface
*/
public function get_data_from_cache($option = null)
{
if($this->get_base_type() == self::DATA_BOX)
{
\cache_databox::refresh($this->id);
}
return $this->get_cache()->get($this->get_cache_key($option));
}

View File

@@ -137,6 +137,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
foreach ($this->retrieve_fields() as $meta_struct_id => $field)
{
if ($field->get_name() == $fieldname)
return $field;
}

View File

@@ -192,7 +192,7 @@ class databox_field implements cache_cacheableInterface
}
catch (Exception $e)
{
}
if ($row['dces_element'])
@@ -234,7 +234,7 @@ class databox_field implements cache_cacheableInterface
/**
*
* @return boolean
* @return boolean
*/
public function isVocabularyRestricted()
{
@@ -677,7 +677,7 @@ class databox_field implements cache_cacheableInterface
}
catch (Exception $e)
{
}
return $this;

View File

@@ -100,6 +100,7 @@ class geonames
$cityName = self::clean_input($cityName);
if (strlen($cityName) === 0)
return $output;
$registry = registry::get_instance();
@@ -140,6 +141,7 @@ class geonames
public function find_geoname_from_ip($ip)
{
if (array_key_exists($ip, $this->cache_ips))
return $this->cache_ips[$ip];
$output = array(

View File

@@ -144,7 +144,7 @@ class mail
public static function mail_confirm_registered($email)
{
$registry = \registry::get_instance();
$subject = _('login::register: sujet email : confirmation de votre adresse email');
$body = "<div>" . _('login::register: merci d\'avoir confirme votre adresse email') . "</div>\n";

View File

@@ -87,6 +87,7 @@ class module_console_fileConfigCheck extends Command
if (!$this->configuration->isInstalled())
{
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
return 1;
}
}
@@ -102,7 +103,7 @@ class module_console_fileConfigCheck extends Command
catch (\Exception $e)
{
$previous = $e->getPrevious();
$output->writeln(sprintf(
"<error>%s FATAL error : %s</error>"
, $e->getMessage()
@@ -111,6 +112,7 @@ class module_console_fileConfigCheck extends Command
)
);
$output->writeln(sprintf("\nConfig check test suite can not continue please correct FATAL error and relaunch.\n"));
return 1;
}
}
@@ -138,6 +140,7 @@ class module_console_fileConfigCheck extends Command
);
}
}
return (int) ($nbErrors > 0);
}

View File

@@ -25,7 +25,7 @@ use Alchemy\Phrasea\Core;
*/
class module_console_fileEnsureProductionSetting extends Command
{
const ALERT = 1;
const ERROR = 0;
@@ -80,6 +80,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (!$this->configuration->isInstalled())
{
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
return 1;
}
}
@@ -104,6 +105,7 @@ class module_console_fileEnsureProductionSetting extends Command
)
);
$output->writeln(sprintf("\nCheck test suite can not continue please correct FATAL error and relaunch.\n"));
return 1;
}
}

View File

@@ -44,12 +44,13 @@ class module_console_schedulerStart extends Command
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php';
try
{
$scheduler = new task_Scheduler();

View File

@@ -39,6 +39,7 @@ class module_console_schedulerState extends Command
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
}
@@ -61,6 +62,7 @@ class module_console_schedulerState extends Command
{
$output->writeln(sprintf('Scheduler is %s', $state['schedstatus']));
}
return 0;
}
catch(\Exception $e)

View File

@@ -39,6 +39,7 @@ class module_console_schedulerStop extends Command
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
}
@@ -49,6 +50,7 @@ class module_console_schedulerStop extends Command
$appbox = appbox::get_instance();
$task_manager = new task_manager($appbox);
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
return 0;
}
catch (\Exception $e)

View File

@@ -46,6 +46,7 @@ class module_console_systemBackupDB extends Command
if (!setup::is_installed())
{
$output->writeln('Argument must be an Id.');
return 1;
}
@@ -56,7 +57,7 @@ class module_console_systemBackupDB extends Command
$appbox = appbox::get_instance();
$ok = true;
$ok = $this->dump_base($appbox, $input, $output) && $ok;
foreach ($appbox->get_databoxes() as $databox)
@@ -96,15 +97,17 @@ class module_console_systemBackupDB extends Command
if (file_exists($filename) && filesize($filename) > 0)
{
$output->writeln('OK');
return true;
}
else
{
$output->writeln('<error>Failed</error>');
return false;
}
}
}

View File

@@ -47,7 +47,7 @@ class module_console_systemClearCache extends Command
__DIR__ . '/../../../../tmp/cache_minify/'
, __DIR__ . '/../../../../tmp/cache_twig/'
));
$count = 1;
foreach ($finder as $file)
{
@@ -64,7 +64,7 @@ class module_console_systemClearCache extends Command
))
->exclude('.git')
->exclude('.svn');
foreach ($finder as $file)
{
$dirs[$file->getPathname()] = $file->getPathname();

View File

@@ -46,7 +46,7 @@ class module_console_systemConfigCheck extends Command
}
$ok = true;
if (setup::is_installed())
{
$registry = registry::get_instance();
@@ -60,7 +60,7 @@ class module_console_systemConfigCheck extends Command
$registry = new Setup_Registry();
}
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
@@ -99,6 +99,7 @@ class module_console_systemConfigCheck extends Command
$hasError = true;
}
}
return !$hasError;
}
@@ -118,6 +119,7 @@ class module_console_systemConfigCheck extends Command
{
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
}
return $ok;
}

View File

@@ -40,6 +40,7 @@ class module_console_tasklist extends Command
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
}
@@ -60,6 +61,7 @@ class module_console_tasklist extends Command
{
$this->print_task($task, $output);
}
return 0;
}
catch (\Exception $e)

View File

@@ -48,6 +48,7 @@ class module_console_taskrun extends Command
if (!setup::is_installed())
{
$output->writeln('Phraseanet is not set up');
return 1;
}
@@ -58,6 +59,7 @@ class module_console_taskrun extends Command
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
{
$output->writeln('Argument must be an Id.');
return 1;
}
@@ -73,9 +75,9 @@ class module_console_taskrun extends Command
{
$runner = task_abstract::RUNNER_MANUAL;
}
$task->run($runner);
return 0;
}
catch (\exception $e)

View File

@@ -64,4 +64,4 @@ class patch_3602 implements patchInterface
return true;
}
}
}

View File

@@ -1736,6 +1736,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{
$hd = $this->get_subdef('document');
if ($hd->is_physically_present())
return new system_file(p4string::addEndSlash($hd->get_path()) . $hd->get_file());
return null;
}

View File

@@ -211,6 +211,7 @@ class record_preview extends record_adapter
public function get_train($pos = 0, $query = '', searchEngine_adapter $search_engine = null)
{
if ($this->train)
return $this->train;
switch ($this->env)
@@ -273,6 +274,7 @@ class record_preview extends record_adapter
public function get_title($highlight = '', searchEngine_adapter $search_engine = null)
{
if ($this->title)
return $this->title;
$this->title = collection::getLogo($this->get_base_id()) . ' ';
@@ -329,6 +331,7 @@ class record_preview extends record_adapter
public function get_short_history()
{
if (!is_null($this->short_history))
return $this->short_history;
$tab = array();
@@ -389,7 +392,7 @@ class record_preview extends record_adapter
}
catch (Exception $e)
{
}
$tab[$hour][$site][$action][$row['usr_id']] =
@@ -421,6 +424,7 @@ class record_preview extends record_adapter
public function get_view_popularity()
{
if (!is_null($this->view_popularity))
return $this->view_popularity;
$appbox = appbox::get_instance();
$session = $appbox->get_session();
@@ -518,6 +522,7 @@ class record_preview extends record_adapter
public function get_refferer_popularity()
{
if (!is_null($this->refferer_popularity))
return $this->refferer_popularity;
$appbox = appbox::get_instance();
$session = $appbox->get_session();
@@ -604,6 +609,7 @@ class record_preview extends record_adapter
{
if (!is_null($this->download_popularity))
return $this->download_popularity;
$appbox = appbox::get_instance();
$session = $appbox->get_session();

View File

@@ -762,6 +762,7 @@ class set_export extends set_abstract
return false;
}
if (isset($list['complete']) && $list['complete'] === true)
return;
@@ -1053,7 +1054,7 @@ class set_export extends set_abstract
$user = false;
if ($anonymous)
{
}
else
{

View File

@@ -614,15 +614,15 @@ class setup
echo '<ul class="setup">';
$registry = registry::get_instance();
if ($registry->get('GV_cache_server_type') !== 'nocache')
{
$cache = cache_adapter::get_instance(registry::get_instance());
if ($cache->ping())
{
$stats = $cache->getStats();
foreach ($stats as $name => $stat)
{
echo '<li>Statistics given by `' . $name . '`</li>';

View File

@@ -63,4 +63,4 @@ class RedisTest extends \PhraseanetPHPUnitAbstract
$this->assertEquals($redis, $cache->getRedis());
}
}
}

View File

@@ -32,7 +32,7 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
$autoloader->loadClass($testClassName);
$this->assertTrue(class_exists($testClassName));
}
public function testAddPath()
{
$autoloader = new Alchemy\Phrasea\Loader\Autoloader();
@@ -41,7 +41,7 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
$this->assertGreaterThan($pathNb, count($autoloader->getPaths()));
$this->assertArrayHasKey('fixture', $autoloader->getPaths());
}
public function testGetPath()
{
$autoloader = new Alchemy\Phrasea\Loader\Autoloader();
@@ -50,4 +50,4 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
$this->assertArrayHasKey('config', $autoloader->getPaths());
$this->assertArrayHasKey('library', $autoloader->getPaths());
}
}
}

View File

@@ -53,7 +53,7 @@ class CacheAutoloaderTest extends \PhraseanetPHPUnitAbstract
}
catch(\Exception $e)
{
}
}
}
@@ -122,4 +122,4 @@ class CacheAutoloaderTest extends \PhraseanetPHPUnitAbstract
parent::tearDown();
}
}
}

View File

@@ -18,5 +18,5 @@
class Test_hello
{
}
}

View File

@@ -18,5 +18,5 @@
class HelloCache
{
}
}

View File

@@ -18,5 +18,5 @@
class Test_test
{
}
}

View File

@@ -36,7 +36,7 @@
var name = $( "#name" ), accessclass = $( "#accessclass" ),
allFields = $( [] ).add( name ).add(accessclass),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
@@ -75,7 +75,7 @@
return true;
}
}
function checkSpecialChar( o )
{
var ok = true;
@@ -87,9 +87,10 @@
o.addClass( "ui-state-error" );
updateTips( "Special characters (except minus) or espaces are not authorized" );
}
return ok;
}
$( "#dialog-form" ).dialog({
autoOpen: false,
@@ -99,14 +100,14 @@
buttons: {
"Create a Subdef": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkLength( name, "subdef name", 3, 16 );
bValid = bValid && checkSpecialChar( name );
bValid = bValid && checkPresence( name );
if ( bValid ) {
$('input[name="add_subdef[group]"]').val(get_current_group());

View File

@@ -82,6 +82,7 @@
role = $(this).val();
shareWith(usr_id, role);
return false;
});
@@ -107,6 +108,7 @@
humane.error(data.message);
}
$dialog.refresh();
return;
},
error: function(){
@@ -137,6 +139,7 @@
{
shareWith(ui.item.usr_id);
}
return false;
}
})
@@ -160,4 +163,4 @@
};
});
</script>
{% endif %}
{% endif %}

View File

@@ -190,4 +190,4 @@
</tr>
</table>
</div>
{% endmacro %}
{% endmacro %}