Skip to content

Commit

Permalink
Phpcbf
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelh78 committed Apr 16, 2024
1 parent 79379e6 commit 84b0263
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 47 deletions.
5 changes: 2 additions & 3 deletions galette/lib/Galette/Controllers/Crud/CrudHelper.php
Expand Up @@ -14,8 +14,8 @@ public static function AddRoutesBasicEntityCRUD(App $app, string $controllerClas
$entity = basename($entity);
$entity = substr($entity, 0, -1);

$baseName=lcfirst($entity);
$basePath=strtolower($entity);
$baseName = lcfirst($entity);
$basePath = strtolower($entity);

$app->get(
"/{$basePath}s",
Expand Down Expand Up @@ -46,7 +46,6 @@ public static function AddRoutesBasicEntityCRUD(App $app, string $controllerClas
"/{$basePath}/edit/{id:\d+}",
[$controllerClassName, 'doEdit']
)->setname("edit{$entity}")->add($authenticate);

}
}

Expand Down
2 changes: 1 addition & 1 deletion galette/lib/Galette/Controllers/Crud/MembersController.php
Expand Up @@ -988,7 +988,7 @@ public function edit(
//Titles
$titles = new Titles($this->zdb);
//LegalStatus
$legalStatus = new LegalStatuss($this->zdb);
$legalStatus = new LegalStatuss($this->zdb);

//Groups
$groups = new Groups($this->zdb, $this->login);
Expand Down
2 changes: 1 addition & 1 deletion galette/lib/Galette/Core/Galette.php
Expand Up @@ -413,7 +413,7 @@ public static function getMenus(bool $public = false): array
'name' => 'legalStatuss',
'aliases' => ['editLegalStatus']
]
],
],
[
'label' => _T("PDF models"),
'title' => _T("Manage PDF models"),
Expand Down
6 changes: 4 additions & 2 deletions galette/lib/Galette/Entity/Adherent.php
Expand Up @@ -130,7 +130,7 @@ class Adherent
private ?int $id;
//Identity
private Title|string|null $title = null;
private int $id_legal_status=LegalStatus::INDIVIDUAL;
private int $id_legal_status = LegalStatus::INDIVIDUAL;
private ?string $company_name;
private ?string $name;
private ?string $surname;
Expand Down Expand Up @@ -1402,7 +1402,9 @@ public function validate(string $field, $value, array $values): void
}
break;
case 'id_legal_status':
if ($value !== '') $this->id_legal_status = intval($value);
if ($value !== '') {
$this->id_legal_status = intval($value);
}
break;
case 'email_adh':
if (!GaletteMail::isValidEmail($value)) {
Expand Down
33 changes: 18 additions & 15 deletions galette/lib/Galette/Entity/Base/EntityFromDb.php
Expand Up @@ -82,8 +82,9 @@ public function load(int $id): void
$results = $this->zdb->execute($select);
$res = $results->current();

if ($res)
if ($res) {
$this->loadFromRs($res);
}
} catch (Throwable $e) {
Analog::log(
"Error when loading {$this->entity} (#$id) Message:\n" .
Expand Down Expand Up @@ -143,7 +144,6 @@ public function store(): bool

try {
if (isset($this->id) && $this->id > 0) {

foreach ($this->i18nProperties as $prop) {
if ($this->oldValues[$prop] !== null) {
$this->deleteTranslation($this->oldValues[$prop]);
Expand Down Expand Up @@ -193,7 +193,7 @@ public function remove(): bool
$delete->where([$this->PK => $this->id]);
$this->zdb->execute($delete);

//I18n
//I18n
foreach ($this->i18nProperties as $prop) {
$this->deleteTranslation($this->values[$prop]);
}
Expand Down Expand Up @@ -229,9 +229,9 @@ public function __get(string $name): mixed
/**
* getValue
*
* @param string $name Property name
* @param string $name Property name
* @param string $translated translate returned string
*
*
* @return mixed
*/
public function getValue(string $name, bool $translated): mixed
Expand All @@ -246,17 +246,17 @@ public function getValue(string $name, bool $translated): mixed
//from other property
$k = "$name:from";
if (self::getOption($k, $f)) {
if (is_callable($f))
if (is_callable($f)) {
$value = $f();
elseif ($f != '')
} elseif ($f != '') {
$value = $this->getValue($f, $translated); //equivalent $this->{$f};
}
$found = true;
}
}

if ($found) //value can be null
{
//override default
if ($found) { //value can be null
//override default
$k = "$name:override";
if (array_key_exists($k, $this->options)) {
$fct = $this->options[$k];
Expand All @@ -269,8 +269,9 @@ public function getValue(string $name, bool $translated): mixed
if (array_key_exists($k, $this->options)) {
$fct = $this->options[$k];

if (!$fct($value))
if (!$fct($value)) {
throw new \Exception($name . ' ' . _T('invalid value !'));
}
}

if ($translated && in_array($name, $this->i18nProperties)) {
Expand Down Expand Up @@ -335,12 +336,14 @@ public function setValue(string $name, $value): void
if (array_key_exists($k, $this->options)) {
$fct = $this->options[$k];

if (!$fct($value))
if (!$fct($value)) {
throw new \Exception($name . ' ' . _T('invalid value !'));
}
}

if (array_key_exists($name, $this->values))
if (array_key_exists($name, $this->values)) {
$this->oldValues[$name] = $this->values[$name];
}
$this->values[$name] = $value;
} else {
Analog::log(
Expand All @@ -352,8 +355,9 @@ public function setValue(string $name, $value): void

private function getOption(string $name, mixed &$option): bool
{
if (!array_key_exists($name, $this->options))
if (!array_key_exists($name, $this->options)) {
return false;
}
$option = $this->options[$name];
return true;
}
Expand All @@ -374,5 +378,4 @@ public function __call($name, $arguments)
}
throw new \RuntimeException("Entity::$name property not available.");
}

}
2 changes: 1 addition & 1 deletion galette/lib/Galette/Entity/Base/Translate.php
Expand Up @@ -8,4 +8,4 @@ public static function getFromLang(string $value): string
{
return _T(strip_tags($value), 'galette', false);
}
}
}
6 changes: 3 additions & 3 deletions galette/lib/Galette/Entity/LegalStatus.php
Expand Up @@ -11,7 +11,7 @@ class LegalStatus extends EntityFromDb
public const TABLE = 'legalstatus';
public const PK = 'id_legalstatus';

public const INDIVIDUAL = 1; //physical member
public const INDIVIDUAL = 1; //physical member

public function __construct(Db $zdb, ArrayObject|int $args = null)
{
Expand All @@ -22,12 +22,12 @@ public function __construct(Db $zdb, ArrayObject|int $args = null)
'id' => self::PK,
'short' => 'short_label',
'long' => 'long_label',
],
],
[
'toString' => 'long',
//Automatic add and removeTranslation() when store()
'i18n' => ['short', 'long']
],
],
$args
);
}
Expand Down
1 change: 0 additions & 1 deletion galette/lib/Galette/Entity/PaymentType.php
Expand Up @@ -137,5 +137,4 @@ public function isSystemType(): bool
{
return isset($this->getSystemTypes()[$this->id]);
}

}
14 changes: 7 additions & 7 deletions galette/lib/Galette/Entity/Title.php
Expand Up @@ -51,17 +51,20 @@ public function __construct(Db $zdb, ArrayObject|int $args = null)

//if long value is null get short value
'long:override' => function ($value) {
return ($value == null || trim($value) === '') ? $this->short : $value; },
return ($value == null || trim($value) === '') ? $this->short : $value;
},
'long:warningnoempty' => true,

//Virtual properties
'tshort:from' => 'short', //OR function() { return $this->short; },
'tshort:from' => 'short', //OR function() { return $this->short; },
'tlong:from' => 'long',

'tshort:override' => function ($value) {
return Translate::getFromLang($value); },
return Translate::getFromLang($value);
},
'tlong:override' => function ($value) {
return Translate::getFromLang($value); },
return Translate::getFromLang($value);
},
],
$args
);
Expand All @@ -83,6 +86,3 @@ public function remove(): bool
return parent::remove();
}
}



1 change: 0 additions & 1 deletion galette/lib/Galette/Repository/LegalStatuss.php
Expand Up @@ -45,5 +45,4 @@ protected function loadDefaults(): array
'long_label' => 'Entreprise'
)];
}

}
7 changes: 4 additions & 3 deletions galette/lib/Galette/Repository/PaymentTypes.php
Expand Up @@ -35,11 +35,12 @@
class PaymentTypes extends Repository
{
use RepositoryTrait;

public const TABLE = PaymentType::TABLE;
public const PK = PaymentType::PK;



/**
* Checks for missing payment types in the database
*
Expand Down Expand Up @@ -88,7 +89,7 @@ protected function checkUpdate(): bool
return false;
}



/**
* Get defaults values
Expand Down
5 changes: 2 additions & 3 deletions galette/lib/Galette/Repository/Repository.php
Expand Up @@ -30,7 +30,6 @@
use Laminas\Db\ResultSet\ResultSet;
use stdClass;


/**
* Repositories
*
Expand Down Expand Up @@ -63,8 +62,8 @@ abstract class Repository
*/
public function __construct(
Db $zdb,
Preferences $preferences=null,
Login $login=null,
Preferences $preferences = null,
Login $login = null,
?string $entity = null,
?string $ns = null,
string $prefix = ''
Expand Down
4 changes: 2 additions & 2 deletions galette/lib/Galette/Repository/RepositoryTrait.php
Expand Up @@ -50,7 +50,7 @@ public function getList(): array|ResultSet
public static function getAll(): array
{
global $zdb;
$ptypes = new self($zdb);
$ptypes = new self($zdb);
return $ptypes->getList();
}

Expand Down Expand Up @@ -157,7 +157,7 @@ protected function checkUpdate(): bool
/**
* Insert values in database
*
* @param string $table Table name
* @param string $table Table name
* @param array<array> $values Values to insert
*
* @return void
Expand Down
5 changes: 1 addition & 4 deletions galette/lib/Galette/Repository/Titles.php
Expand Up @@ -35,6 +35,7 @@
class Titles extends Repository
{
use RepositoryTrait;

public const TABLE = 'titles';
public const PK = 'id_title';

Expand Down Expand Up @@ -63,10 +64,6 @@ protected function loadDefaults(): array
];
}






/**
* Set default titles at install time
Expand Down

0 comments on commit 84b0263

Please sign in to comment.