Commit fec8cbf3 authored by Александр Плохих's avatar Александр Плохих 🌔
Browse files

Merge branch 'main' into 'PTPS|Function_8'

# Conflicts:
#   public/public/TestData/TestData.php
#   public/public/index.php
parents 5e4894f8 5c62a953
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

use DateTimeImmutable;

class CountFriday13
{
    /**
     * Вернет все пятницы 13 в году
     * @param int $year год, в котором необходимо произвести расчет
     * @return DateTimeImmutable[]
     */
    public static function count(int $year): array
    {
        $AllFri13 = [];

        for ($i = 1; $i <= 12; $i++) {
            $next13 = (new DateTimeImmutable())->setDate($year, $i, 13);

            if ($next13->format("D") === "Fri") {
                $AllFri13[] = $next13;
            }
        }
        return $AllFri13;
    }
}
+21 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

use DateTimeImmutable;

class DiffDaysAction
{
    /**
     * Вернет кол-во дней между датами
     * @param DateTimeImmutable $dateStart дата начала
     * @param DateTimeImmutable $dateEnd дата окончания
     * @return int
     * */
    public static function count(
        DateTimeImmutable $dateStart,
        DateTimeImmutable $dateEnd
    ): int {
        return (int) $dateStart->diff($dateEnd)->format('%a');
    }
}
+20 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

use DateTimeImmutable;

class HowDaysToNYAction
{
    /**
     * Функция рассчитывает кол-во дней до нового года
     * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней
     * @return int
     */
    public static function count(DateTimeImmutable $date): int
    {
        $dateOfNY = $date->modify('first day of Jan +1 year');

        return (int) $dateOfNY->diff($date)->format('%a');
    }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

class SortPriceAction
{
    /**
     * Выполняет сортировку массива по убыванию цены
     * @param array $array
     * @return array отсортированный
     */
    public static function sort(array $array)
    {
        $priceColumn = array_column($array, "price");
        $countColumn = array_column($array, "count");

        array_multisort(
            $priceColumn,
            SORT_DESC,
            $countColumn,
            SORT_ASC,
            $array
        );

        return $array;
    }
}
+28 −0
Original line number Diff line number Diff line
@@ -10,6 +10,34 @@ class TestData
{
    public const FILE_PATH = "TestData/FileToRead.txt";

    public const START_DATE = "13.04.2024";
    public const END_DATE = "13.04.2025";

    public const YEAR = 2024;

    public const PRICE_COUNT_ARRAY = [
        [
            'price' => 4,
            'count' => 2,
        ],
        [
            'price' => 4,
            'count' => 1,
        ],
        [
            'price' => 2,
            'count' => 10,
        ],
        [
            'price' => 1,
            'count' => 4,
        ],
        [
            'price' => 3,
            'count' => 4,
        ],
    ];

    public const RAW_MENU = [
        [
            'name' => 'Смартфоны и гаджеты',
Loading