Skip to content

Commit

Permalink
phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Aug 23, 2024
1 parent cecb727 commit 6fc9847
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function edit(Request $request, Response $response, int $id = null, strin
$activity = $this->session->activity;
$this->session->activity = null;
} else {
$activity = new Activity($this->zdb, $this->login);
$activity = new Activity($this->zdb);
}

if ($id !== null && $activity->getId() != $id) {
Expand Down Expand Up @@ -236,7 +236,7 @@ public function edit(Request $request, Response $response, int $id = null, strin
public function doEdit(Request $request, Response $response, int $id = null, string $action = 'edit'): Response
{
$post = $request->getParsedBody();
$activity = new Activity($this->zdb, $this->login);
$activity = new Activity($this->zdb);
if (isset($post['id']) && !empty($post['id'])) {
$activity->load((int)$post['id']);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ public function formUri(array $args): string
*/
public function confirmRemoveTitle(array $args): string
{
$activity = new Activity($this->zdb, $this->login, (int)$args['id']);
$activity = new Activity($this->zdb, (int)$args['id']);
return sprintf(
//TRANS %1$s is activity name
_T('Remove activity %1$s', 'activities'),
Expand All @@ -368,7 +368,7 @@ public function confirmRemoveTitle(array $args): string
*/
protected function doDelete(array $args, array $post): bool
{
$activity = new Activity($this->zdb, $this->login, (int)$args['id']);
$activity = new Activity($this->zdb, (int)$args['id']);
return $activity->remove();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public function list(Request $request, Response $response, string $option = null

$activity = null;
if ($filters->activity_filter) {
$activity = new Activity($this->zdb, $this->login, (int)$filters->activity_filter);
$activity = new Activity($this->zdb, (int)$filters->activity_filter);
}

//Groups
$groups = new Groups($this->zdb, $this->login);
$groups_list = $groups->getList();

$subscriptions = new Subscriptions($this->zdb, $this->login, $filters);
$subscriptions = new Subscriptions($this->zdb, $filters);

$activities = new Activities($this->zdb, $this->login, $this->preferences);
$list = $subscriptions->getList();
Expand Down Expand Up @@ -258,7 +258,7 @@ public function edit(Request $request, Response $response, int $id = null, strin
$subscription = $this->session->subscription;
$this->session->subscription = null;
} else {
$subscription = new Subscription($this->zdb, $this->login);
$subscription = new Subscription($this->zdb);
}

if ($id !== null && $subscription->getId() != $id) {
Expand Down Expand Up @@ -309,7 +309,7 @@ public function edit(Request $request, Response $response, int $id = null, strin
'autocomplete' => true,
'page_title' => $title,
'subscription' => $subscription,
'activities' => $activities->getList(true),
'activities' => $activities->getList(),
'require_dialog' => true,
'require_calendar' => true,
// pseudo random int
Expand All @@ -333,7 +333,7 @@ public function edit(Request $request, Response $response, int $id = null, strin
public function doEdit(Request $request, Response $response, int $id = null, string $action = 'edit'): Response
{
$post = $request->getParsedBody();
$subscription = new Subscription($this->zdb, $this->login);
$subscription = new Subscription($this->zdb);
if (isset($post['id']) && !empty($post['id'])) {
$subscription->load((int)$post['id']);
}
Expand Down Expand Up @@ -483,7 +483,7 @@ public function formUri(array $args): string
*/
public function confirmRemoveTitle(array $args): string
{
$subscription = new Subscription($this->zdb, $this->login, (int)$args['id']);
$subscription = new Subscription($this->zdb, (int)$args['id']);
$member = $subscription->getMember();
$activity = $subscription->getActivity();
return sprintf(
Expand All @@ -504,7 +504,7 @@ public function confirmRemoveTitle(array $args): string
*/
protected function doDelete(array $args, array $post): bool
{
$subscription = new Subscription($this->zdb, $this->login, (int)$post['id']);
$subscription = new Subscription($this->zdb, (int)$post['id']);
return $subscription->remove();
}

Expand Down
13 changes: 5 additions & 8 deletions lib/GaletteActivities/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Activity
public const PK = 'id_activity';

private Db $zdb;
private Login $login;
/** @var array<string> */
private array $errors = [];

Expand All @@ -60,16 +59,14 @@ class Activity
/**
* Default constructor
*
* @param Db $zdb Database instance
* @param Login $login Login instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific activity, or null to just
* instanciate object
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific activity, or null to just
* instanciate object
*/
public function __construct(Db $zdb, Login $login, int|ArrayObject $args = null)
public function __construct(Db $zdb, int|ArrayObject $args = null)
{
$this->zdb = $zdb;
$this->login = $login;
$this->setFields();

if (is_int($args) && $args > 0) {
Expand Down
21 changes: 9 additions & 12 deletions lib/GaletteActivities/Entity/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Subscription
public const PK = 'id_subscription';

private Db $zdb;
private Login $login;
/** @var array<string> */
private array $errors;

Expand All @@ -65,16 +64,14 @@ class Subscription
/**
* Default constructor
*
* @param Db $zdb Database instance
* @param Login $login Login instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific subscription, or null to just
* instanciate object
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific subscription, or null to just
* instanciate object
*/
public function __construct(Db $zdb, Login $login, int|ArrayObject|null $args = null)
public function __construct(Db $zdb, int|ArrayObject|null $args = null)
{
$this->zdb = $zdb;
$this->login = $login;
$this->setFields();

if (is_int($args)) {
Expand Down Expand Up @@ -179,9 +176,9 @@ public function remove(): bool
* @param array<string,mixed> $values All values to check, basically the $_POST array
* after sending the form
*
* @return true|array<string>
* @return boolean
*/
public function check(array $values): array|bool
public function check(array $values): bool
{
$this->errors = array();

Expand Down Expand Up @@ -356,7 +353,7 @@ public function getActivityId(): ?int
public function getActivity(): ?Activity
{
if (isset($this->id_activity)) {
$this->activity = new Activity($this->zdb, $this->login, $this->id_activity);
$this->activity = new Activity($this->zdb, $this->id_activity);
}
return $this->activity;
}
Expand Down Expand Up @@ -471,7 +468,7 @@ public function getEndDate(bool $formatted = true): string
public function setActivity(int $activity): self
{
$this->id_activity = $activity;
$this->activity = new Activity($this->zdb, $this->login, $this->id_activity);
$this->activity = new Activity($this->zdb, $this->id_activity);
return $this;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/GaletteActivities/Filters/SubscriptionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
* @property int $paid_filter
* @property int $payment_type_filter
* @property int $date_field
* @property array<int> $selected
* @property string $query
*/
class SubscriptionsList extends Pagination
{
Expand Down
2 changes: 1 addition & 1 deletion lib/GaletteActivities/Repository/Activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getList(): array|ResultSet

$activities = [];
foreach ($results as $row) {
$activity = new Activity($this->zdb, $this->login, $row);
$activity = new Activity($this->zdb, $row);
$activities[] = $activity;
}

Expand Down
7 changes: 2 additions & 5 deletions lib/GaletteActivities/Repository/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
class Subscriptions
{
private Db $zdb;
private Login $login;
private SubscriptionsList $filters;
private int $count;
private float $sum;
Expand All @@ -64,13 +63,11 @@ class Subscriptions
* Constructor
*
* @param Db $zdb Database instance
* @param Login $login Login instance
* @param ?SubscriptionsList $filters Filtering
*/
public function __construct(Db $zdb, Login $login, SubscriptionsList $filters = null)
public function __construct(Db $zdb, SubscriptionsList $filters = null)
{
$this->zdb = $zdb;
$this->login = $login;

if ($filters === null) {
$this->filters = new SubscriptionsList();
Expand Down Expand Up @@ -102,7 +99,7 @@ public function getList(bool $full = false): array

$subscriptions = [];
foreach ($results as $row) {
$subscription = new Subscription($this->zdb, $this->login, $row);
$subscription = new Subscription($this->zdb, $row);
$subscriptions[] = $subscription;
}

Expand Down
18 changes: 18 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 5
paths:
- lib/
scanFiles:
- _config.inc.php
- ../../includes/sys_config/paths.inc.php
- ../../config/config.inc.php.dist
- ../../includes/sys_config/galette_tcpdf_config.php
scanDirectories:
- ../../includes/
- ../../lib/
universalObjectCratesClasses:
- RKA\Session
ignoreErrors:
- '/Access to an undefined property ArrayObject.*/'
8 changes: 4 additions & 4 deletions tests/GaletteActivities/Entity/tests/units/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function tearDown(): void
*/
public function testEmpty(): void
{
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $this->login);
$activity = new \GaletteActivities\Entity\Activity($this->zdb);

$this->assertNull($activity->getId());
$this->assertSame('',$activity->getName());
Expand All @@ -73,7 +73,7 @@ public function testEmpty(): void
*/
public function testCrud(): void
{
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $this->login);
$activity = new \GaletteActivities\Entity\Activity($this->zdb);
$activities = new \GaletteActivities\Repository\Activities($this->zdb, $this->login, $this->preferences);

//ensure the table is empty
Expand Down Expand Up @@ -140,7 +140,7 @@ public function testCrud(): void
$data['id_group'] = $group->getId();
$this->assertTrue($activity->check($data));
$this->assertTrue($activity->store());
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $this->login, $first_id);
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $first_id);

$this->assertInstanceOf(\Galette\Entity\Group::class, $activity->getGroup());
$this->assertSame($group->getId(), $activity->getGroup()->getId());
Expand All @@ -157,7 +157,7 @@ public function testCrud(): void
*/
public function testLoadError(): void
{
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $this->login);
$activity = new \GaletteActivities\Entity\Activity($this->zdb);
$this->assertFalse($activity->load(999));
}
}
10 changes: 5 additions & 5 deletions tests/GaletteActivities/Entity/tests/units/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function tearDown(): void
*/
public function testEmpty(): void
{
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb, $this->login);
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb);

$this->assertNull($subscription->getId());
$this->assertNull($subscription->getActivityId());
Expand All @@ -85,14 +85,14 @@ public function testEmpty(): void
*/
public function testCrud(): void
{
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb, $this->login);
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb);
$subscriptions = new \GaletteActivities\Repository\Activities($this->zdb, $this->login, $this->preferences);

//ensure the table is empty
$this->assertCount(0, $subscriptions->getList());

//bootstrap data
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $this->login);
$activity = new \GaletteActivities\Entity\Activity($this->zdb);
$data = [
'name' => 'Activity for subscriptions',
'comment' => 'Comment ' . $this->seed,
Expand Down Expand Up @@ -186,7 +186,7 @@ public function testCrud(): void
$this->assertSame($member_one->id, $subscription->getMember()->id);

//reload
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb, $this->login, $subscription_id);
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb, $subscription_id);
$data += [
'paid' => 1,
'payment_amount' => 21.0,
Expand All @@ -213,7 +213,7 @@ public function testCrud(): void
*/
public function testLoadError(): void
{
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb, $this->login);
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb);
$this->assertFalse($subscription->load(999));
}
}

0 comments on commit 6fc9847

Please sign in to comment.