Skip to content

Commit

Permalink
Bump php + auditor
Browse files Browse the repository at this point in the history
  • Loading branch information
a-menshchikov committed Jun 13, 2024
1 parent 4c86160 commit b33a497
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:
echo "::endgroup::"
- name: Auditor
uses: docker://nbgrp/auditor:0.20.0
uses: docker://nbgrp/auditor:0.26.0
with:
working-directory: shared/homeless
4 changes: 2 additions & 2 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3.2-fpm-alpine
FROM php:8.3.8-fpm-alpine

#
# Setup Moscow time
Expand Down Expand Up @@ -36,7 +36,7 @@ RUN apk update \
nodejs \
yarn \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& composer self-update 2.5.1 \
&& composer self-update 2.7.1 \
&& docker-php-ext-install \
bcmath \
gd \
Expand Down
2 changes: 1 addition & 1 deletion docker/local/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3.2-fpm-alpine
FROM php:8.3.8-fpm-alpine

USER root

Expand Down
16 changes: 11 additions & 5 deletions shared/homeless/src/Admin/ClientAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ public function configureShowFields(ShowMapper $show): void
}

$field = $fieldValue->getField();
$fieldCode = $field->getCode();

$options = ['label' => $field->getName()];
$options = [
'label' => $field->getName(),
'accessor' => static fn (Client $client): mixed => $client->getAdditionalFieldValue($fieldCode),
];

switch ($field->getType()) {
case ClientField::TYPE_OPTION:
Expand All @@ -242,12 +246,12 @@ public function configureShowFields(ShowMapper $show): void
break;
}

if ($field->getCode() === 'homelessFrom') {
if ($fieldCode === 'homelessFrom') {
$options['pattern'] = 'MMM y';
}

$showMapperAdditionalInfo[\count($showMapperAdditionalInfo) - 1]['add'] = [
self::getAdditionalFieldName($field->getCode()),
self::getAdditionalFieldName($fieldCode),
$field->getShowFieldType(),
$options,
];
Expand All @@ -262,8 +266,7 @@ public function configureShowFields(ShowMapper $show): void
foreach ($showMapperAdditionalInfoSort as $showMapperAdditionalInfoSortItems) {
foreach ($showMapperAdditionalInfoSortItems as $item) {
if (isset($item['add'])) {
$reflectionMethod = new \ReflectionMethod(ShowMapper::class, 'add');
$reflectionMethod->invokeArgs($show, $item['add']);
$show->add(...$item['add']);
}
}
}
Expand Down Expand Up @@ -545,6 +548,8 @@ protected function configureFormFields(FormMapper $form): void
'label' => 'Не бездомный',
'label_attr' => ['class' => 'changeSelectinsData'],
'required' => false,
'getter' => static fn (Client $client): bool => !$client->isHomeless(),
'setter' => static fn (Client $client, bool $value): Client => $client->setIsHomeless(!$value),
])
;
}
Expand Down Expand Up @@ -676,6 +681,7 @@ protected function configureListFields(ListMapper $list): void
->add('lastContractDuration', null, [
'template' => '/admin/fields/client_contract_duration_list.html.twig',
'label' => ' ',
'virtual_field' => true,
])
->addIdentifier('id', 'number', [
'route' => ['name' => 'show'],
Expand Down
3 changes: 2 additions & 1 deletion shared/homeless/src/Admin/ContractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function configureFormFields(FormMapper $form): void
->add('duration', AppContractDurationType::class, [
'label' => 'Долгосрочность',
'required' => false,
'setter' => static fn () => null,
])
->add('number', null, [
'label' => 'Номер',
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function configureFormFields(FormMapper $form): void
protected function configureListFields(ListMapper $list): void
{
$list
->add('duration', 'number', [
->add('duration', null, [
'template' => '/admin/fields/contract_duration_list.html.twig',
'label' => ' ',
])
Expand Down
26 changes: 0 additions & 26 deletions shared/homeless/src/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,6 @@ public function __toString(): string
return $this->getFullname();
}

public function __call($name, $args): mixed
{
$property = lcfirst(substr($name, 3));
if (str_starts_with($name, 'get') && str_starts_with($property, 'additionalField')) {
return $this->getAdditionalFieldValue(substr($property, 15));
}

if (str_starts_with($name, 'set') && str_starts_with($property, 'additionalField')) {
$this->setAdditionalFieldValue(substr($name, 15), \count($args) === 1 ? $args[0] : null);
}

return null;
}

public function getPhoto(): ?File
{
return $this->photo;
Expand Down Expand Up @@ -623,18 +609,6 @@ public function setIsHomeless(bool $isHomeless): self
return $this;
}

public function notIsHomeless(): bool
{
return !$this->isHomeless;
}

public function setNotIsHomeless(bool $notIsHomeless): self
{
$this->isHomeless = !$notIsHomeless;

return $this;
}

public function getClientViews(): Collection
{
return $this->clientViews;
Expand Down
80 changes: 33 additions & 47 deletions shared/homeless/src/Service/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,22 @@ public function getClients(
AND c.created_at >= :createClientdateFrom
AND c.created_at <= :createClientFromTo
');
$parameters = [
':createServicedateFrom' => $createServicedateFrom ? date('Y-m-d', strtotime($createServicedateFrom)) : '1960-01-01',
':createServiceFromTo' => $createServiceFromTo ? date('Y-m-d', strtotime($createServiceFromTo)) : date('Y-m-d'),
':createClientdateFrom' => $createClientdateFrom ? date('Y-m-d', strtotime($createClientdateFrom)) : '1960-01-01',
':createClientFromTo' => $createClientFromTo ? date('Y-m-d', strtotime($createClientFromTo)) : date('Y-m-d'),
];
$stmt->bindValue(':createServicedateFrom', $createServicedateFrom ? date('Y-m-d', strtotime($createServicedateFrom)) : '1960-01-01');
$stmt->bindValue(':createServiceFromTo', $createServiceFromTo ? date('Y-m-d', strtotime($createServiceFromTo)) : date('Y-m-d'));
$stmt->bindValue(':createClientdateFrom', $createClientdateFrom ? date('Y-m-d', strtotime($createClientdateFrom)) : '1960-01-01');
$stmt->bindValue(':createClientFromTo', $createClientFromTo ? date('Y-m-d', strtotime($createClientFromTo)) : date('Y-m-d'));
} else {
$stmt = $this->entityManager->getConnection()->prepare('
SELECT c.id
FROM client c
WHERE c.created_at >= :createClientdateFrom
AND c.created_at <= :createClientFromTo
');
$parameters = [
':createClientdateFrom' => $createClientdateFrom ? date('Y-m-d', strtotime($createClientdateFrom)) : '1960-01-01',
':createClientFromTo' => $createClientFromTo ? date('Y-m-d', strtotime($createClientFromTo)) : date('Y-m-d'),
];
$stmt->bindValue(':createClientdateFrom', $createClientdateFrom ? date('Y-m-d', strtotime($createClientdateFrom)) : '1960-01-01');
$stmt->bindValue(':createClientFromTo', $createClientFromTo ? date('Y-m-d', strtotime($createClientFromTo)) : date('Y-m-d'));
}

return $stmt->executeQuery($parameters)->fetchAllAssociative();
return $stmt->executeQuery()->fetchAllAssociative();
}

/**
Expand All @@ -157,7 +153,7 @@ private function oneOffServices(
'скольким людям она была предоставлена',
'сумма',
]]);
$statement = $this->entityManager->getConnection()->prepare('
$stmt = $this->entityManager->getConnection()->prepare('
SELECT
st.name,
COUNT(DISTINCT s.id) all_count,
Expand All @@ -170,15 +166,13 @@ private function oneOffServices(
GROUP BY st.id
ORDER BY st.sort
');
$parameters = [
'dateFrom' => $dateFrom ?: '1960-01-01',
'dateTo' => $dateTo ?: date('Y-m-d'),
];
$stmt->bindValue(':dateFrom', $dateFrom ?: '1960-01-01');
$stmt->bindValue(':dateTo', $dateTo ?: date('Y-m-d'));
if ($userId) {
$parameters['userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $statement->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand Down Expand Up @@ -210,15 +204,13 @@ private function completedItems(
GROUP BY i.type_id
ORDER BY cit.sort
');
$parameters = [
':dateFrom' => $dateFrom ?: '1960-01-01',
':dateTo' => $dateTo ?: date('Y-m-d'),
];
$stmt->bindValue(':dateFrom', $dateFrom ?: '1960-01-01');
$stmt->bindValue(':dateTo', $dateTo ?: date('Y-m-d'));
if ($userId) {
$parameters[':userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $stmt->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand Down Expand Up @@ -275,15 +267,13 @@ private function outgoing(
GROUP BY con.id, h.id
ORDER BY h.date_to DESC
');
$parameters = [
':dateFrom' => $dateFrom ?: '1960-01-01',
':dateTo' => $dateTo ?: date('Y-m-d'),
];
$stmt->bindValue(':dateFrom', $dateFrom ?: '1960-01-01');
$stmt->bindValue(':dateTo', $dateTo ?: date('Y-m-d'));
if ($userId) {
$parameters[':userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $stmt->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand Down Expand Up @@ -334,15 +324,13 @@ private function resultsOfSupport(
GROUP BY con.id
ORDER BY con.date_to DESC
');
$parameters = [
':dateFrom' => $dateFrom ?: '1960-01-01',
':dateTo' => $dateTo ?: date('Y-m-d'),
];
$stmt->bindValue(':dateFrom', $dateFrom ?: '1960-01-01');
$stmt->bindValue(':dateTo', $dateTo ?: date('Y-m-d'));
if ($userId) {
$parameters[':userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $stmt->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand Down Expand Up @@ -385,12 +373,11 @@ private function accompanying(mixed $userId): array
GROUP BY con.id
ORDER BY con.date_to DESC
');
$parameters = [];
if ($userId) {
$parameters[':userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $stmt->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand All @@ -408,7 +395,7 @@ private function averageCompletedItems(
]]);
$stmt = $this->entityManager->getConnection()->prepare('
SELECT cit.name,
FLOOR(AVG (TO_DAYS(c.date_to) - TO_DAYS(c.date_from))) avg_days
FLOOR(AVG(TO_DAYS(c.date_to) - TO_DAYS(c.date_from))) avg_days
FROM contract_item i
JOIN contract c
ON i.contract_id = c.id
Expand All @@ -418,16 +405,15 @@ private function averageCompletedItems(
AND i.date <= :dateTo
'.($userId ? 'AND ((i.created_by_id IS NOT NULL AND i.created_by_id = :userId) OR (i.created_by_id IS NULL AND c.created_by_id = :userId))' : '').'
GROUP BY cit.name
ORDER BY cit.name');
$parameters = [
':dateFrom' => $dateFrom ?: '2000-01-01',
':dateTo' => $dateTo ?: date('Y-m-d'),
];
ORDER BY cit.name
');
$stmt->bindValue(':dateFrom', $dateFrom ?: '2000-01-01');
$stmt->bindValue(':dateTo', $dateTo ?: date('Y-m-d'));
if ($userId) {
$parameters[':userId'] = $userId;
$stmt->bindValue(':userId', $userId);
}

return $stmt->executeQuery($parameters)->fetchAllNumeric();
return $stmt->executeQuery()->fetchAllNumeric();
}

/**
Expand Down

0 comments on commit b33a497

Please sign in to comment.