Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -35,15 +35,11 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
*/
trait AttachmentCollection
{
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameContains(string $name): GroupCollectorInterface
{
$this->hasAttachments();
$this->withAttachmentInformation();
/**
* @param int $index
* @param array $object
@@ -64,6 +60,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -73,8 +70,6 @@ trait AttachmentCollection
/**
* Has attachments
*
* @return GroupCollectorInterface
*/
public function hasAttachments(): GroupCollectorInterface
{
@@ -86,29 +81,6 @@ trait AttachmentCollection
return $this;
}
/**
* Join table to get attachment information.
*/
private function joinAttachmentTables(): void
{
if (false === $this->hasJoinedAttTables) {
// join some extra tables:
$this->hasJoinedAttTables = true;
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
->where(
static function (EloquentBuilder $q1) { // @phpstan-ignore-line
$q1->where('attachments.attachable_type', TransactionJournal::class);
$q1->where('attachments.uploaded', true);
$q1->whereNull('attachments.deleted_at');
$q1->orWhereNull('attachments.attachable_type');
}
);
}
}
/**
* @inheritDoc
*/
public function withAttachmentInformation(): GroupCollectorInterface
{
$this->fields[] = 'attachments.id as attachment_id';
@@ -120,20 +92,17 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameDoesNotContain(string $name): GroupCollectorInterface
{
$this->hasAttachments();
$this->withAttachmentInformation();
/**
* @param int $index
* @param array $object
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
$filter = static function (array $object) use ($name): bool {
@@ -150,6 +119,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -157,20 +127,17 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameDoesNotEnd(string $name): GroupCollectorInterface
{
$this->hasAttachments();
$this->withAttachmentInformation();
/**
* @param int $index
* @param array $object
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
$filter = static function (array $object) use ($name): bool {
@@ -187,6 +154,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -194,20 +162,17 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameDoesNotStart(string $name): GroupCollectorInterface
{
$this->hasAttachments();
$this->withAttachmentInformation();
/**
* @param int $index
* @param array $object
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
$filter = static function (array $object) use ($name): bool {
@@ -224,6 +189,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -231,11 +197,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameEnds(string $name): GroupCollectorInterface
{
$this->hasAttachments();
@@ -254,6 +215,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -261,11 +223,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameIs(string $name): GroupCollectorInterface
{
$this->hasAttachments();
@@ -281,6 +238,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -288,11 +246,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameIsNot(string $name): GroupCollectorInterface
{
$this->hasAttachments();
@@ -308,6 +261,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -315,11 +269,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $name
*
* @return GroupCollectorInterface
*/
public function attachmentNameStarts(string $name): GroupCollectorInterface
{
$this->hasAttachments();
@@ -338,6 +287,7 @@ trait AttachmentCollection
}
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -345,11 +295,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesAre(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -359,12 +304,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && $notes === $value;
return '' !== $notes && $notes === $value;
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -372,11 +319,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesAreNot(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -386,12 +328,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && $notes !== $value;
return '' !== $notes && $notes !== $value;
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -399,11 +343,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesContains(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -413,12 +352,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_contains(strtolower($notes), strtolower($value));
return '' !== $notes && str_contains(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -426,11 +367,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesDoNotContain(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -440,12 +376,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_contains(strtolower($notes), strtolower($value));
return '' !== $notes && !str_contains(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -453,11 +391,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesDoNotEnd(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -467,12 +400,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_ends_with(strtolower($notes), strtolower($value));
return '' !== $notes && !str_ends_with(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -480,11 +415,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesDoNotStart(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -494,12 +424,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_starts_with(strtolower($notes), strtolower($value));
return '' !== $notes && !str_starts_with(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -507,11 +439,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesEnds(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -521,12 +448,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_ends_with(strtolower($notes), strtolower($value));
return '' !== $notes && str_ends_with(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -534,11 +463,6 @@ trait AttachmentCollection
return $this;
}
/**
* @param string $value
*
* @return GroupCollectorInterface
*/
public function attachmentNotesStarts(string $value): GroupCollectorInterface
{
$this->hasAttachments();
@@ -548,12 +472,14 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment|null $object */
/** @var null|Attachment $object */
$object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_starts_with(strtolower($notes), strtolower($value));
return '' !== $notes && str_starts_with(strtolower($notes), strtolower($value));
}
}
return false;
};
$this->postFilters[] = $filter;
@@ -563,8 +489,6 @@ trait AttachmentCollection
/**
* Has attachments
*
* @return GroupCollectorInterface
*/
public function hasNoAttachments(): GroupCollectorInterface
{
@@ -577,13 +501,35 @@ trait AttachmentCollection
->orWhere(static function (Builder $q2) {
$q2
->whereNotNull('attachments.attachable_id')
->whereNotNull('attachments.deleted_at');
->whereNotNull('attachments.deleted_at')
;
// id is not null
// deleted at is not null.
});
})
;
});
return $this;
}
/**
* Join table to get attachment information.
*/
private function joinAttachmentTables(): void
{
if (false === $this->hasJoinedAttTables) {
// join some extra tables:
$this->hasJoinedAttTables = true;
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
->where(
static function (EloquentBuilder $q1) { // @phpstan-ignore-line
$q1->where('attachments.attachable_type', TransactionJournal::class);
$q1->where('attachments.uploaded', true);
$q1->whereNull('attachments.deleted_at');
$q1->orWhereNull('attachments.attachable_type');
}
)
;
}
}
}