Skip to content

Commit

Permalink
Merge pull request #2450 from Leantime/phpstan-lvl0
Browse files Browse the repository at this point in the history
Phpstan lvl0
  • Loading branch information
marcelfolaron authored Apr 2, 2024
2 parents 824bd34 + 3e7b5b0 commit 7e4c255
Show file tree
Hide file tree
Showing 41 changed files with 550 additions and 520 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/staticAnalysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Static Analysis

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
phpstan:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run Tests
run: make phpstan
5 changes: 4 additions & 1 deletion app/Core/ConsoleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Console\Application as ConsoleApplicationContract;
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Foundation\Bus;
use Illuminate\Support\Arr;
use Illuminate\Support\ProcessUtils;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -238,9 +239,11 @@ public function call($command, array $parameters = [], $outputBuffer = null)
* @param array $parameters
* @todo Implement
*/
/** @phpstan-ignore-next-line */
public function queue($command, array $parameters = []): \Illuminate\Foundation\Bus\PendingDispatch
{
return new \Illuminate\Foundation\Bus\PendingDispatch();
/** @phpstan-ignore-next-line */
return \Illuminate\Foundation\Bus\PendingDispatch();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Core/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function render($request, Throwable $e)
*/
public function renderForConsole($output, Throwable $e)
{
(new \Illuminate\Console\Application())->renderThrowable($e, $output);
app()->renderThrowable($e, $output);
}

}
2 changes: 1 addition & 1 deletion app/Core/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class Repository
* @param array $args - usually the value of func_get_args(), gives events/filters values to work with
* @return object
*/
protected function dbcall(array $args): object
protected function dbcall(array ...$args): object
{
return new class ($args, $this) {
/**
Expand Down
2 changes: 2 additions & 0 deletions app/Domain/Api/Controllers/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function patch(array $params): Response

return $this->tpl->displayJson(['status' => 'ok']);
}

return new Response();
}


Expand Down
2 changes: 2 additions & 0 deletions app/Domain/Api/Controllers/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function get(array $params): Response
**/
$this->apiService->jsonResponse(1, $results);
}

return new Response();
}

/**
Expand Down
1 change: 0 additions & 1 deletion app/Domain/Calendar/Controllers/ExternalCal.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function init(CalendarRepository $calendarRepo): void
*
* @throws BindingResolutionException
*/
#[NoReturn]
public function run(): void
{

Expand Down
26 changes: 20 additions & 6 deletions app/Domain/Calendar/Repositories/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class Calendar extends RepositoryCore
{
private array $classColorMap = array(
public array $classColorMap = array(
"label-warning" => "var(--yellow)",
"label-purple" => "var(--purple)",
"label-pink" => "var(--pink)",
Expand Down Expand Up @@ -76,17 +76,23 @@ public function getAllDates(?CarbonImmutable $dateFrom, ?CarbonImmutable $dateTo

if (!empty($dateFrom)) {
$query .= " AND dateFrom >= :dateFrom";
$stmn->bindValue(':dateFrom', $dateFrom->format('Y-m-d H:i:s'), PDO::PARAM_STR);
}

if (!empty($dateTo)) {
$query .= " AND dateTo <= :dateTo";
$stmn->bindValue(':dateTo', $dateTo->format('Y-m-d H:i:s'), PDO::PARAM_STR);
}

$query .= " ORDER BY zp_calendar.dateFrom";

$stmn = $this->db->database->prepare($query);

if (!empty($dateFrom)) {
$stmn->bindValue(':dateFrom', $dateFrom->format('Y-m-d H:i:s'), PDO::PARAM_STR);
}

if (!empty($dateTo)) {
$stmn->bindValue(':dateTo', $dateTo->format('Y-m-d H:i:s'), PDO::PARAM_STR);
}
$stmn->bindValue(':userId', $_SESSION['userdata']['id'], PDO::PARAM_INT);

$stmn->execute();
Expand All @@ -113,23 +119,31 @@ public function getAll(?int $userId, ?CarbonImmutable $dateFrom, ?CarbonImmutabl

if (!empty($userId)) {
$query .= " AND userId >= :userId";
$stmn->bindValue(':userId', $userId, PDO::PARAM_INT);
}

if (!empty($dateFrom)) {
$query .= " AND dateFrom >= :dateFrom";
$stmn->bindValue(':dateFrom', $dateFrom->formatDateTimeForDb(), PDO::PARAM_STR);
}

if (!empty($dateTo)) {
$query .= " AND dateTo <= :dateTo";
$stmn->bindValue(':dateTo', $dateTo->formatDateTimeForDb(), PDO::PARAM_STR);
}

$query .= " ORDER BY zp_calendar.dateFrom";

$stmn = $this->db->database->prepare($query);

if (!empty($userId)) {
$stmn->bindValue(':userId', $userId, PDO::PARAM_INT);
}

if (!empty($dateFrom)) {
$stmn->bindValue(':dateFrom', $dateFrom->formatDateTimeForDb(), PDO::PARAM_STR);
}

if (!empty($dateTo)) {
$stmn->bindValue(':dateTo', $dateTo->formatDateTimeForDb(), PDO::PARAM_STR);
}

$stmn->execute();

Expand Down
47 changes: 46 additions & 1 deletion app/Domain/Calendar/Services/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function getCalendar(int $userId): array

if (isset($statusLabelsArray[$ticket['projectId']][$ticket['status']])) {
$statusName = $statusLabelsArray[$ticket['projectId']][$ticket['status']]["name"];
$statusColor = $this->classColorMap[$statusLabelsArray[$ticket['projectId']][$ticket['status']]["class"]];
$statusColor = $this->calendarRepo->classColorMap[$statusLabelsArray[$ticket['projectId']][$ticket['status']]["class"]];
} else {
$statusName = "";
$statusColor = "var(--grey)";
Expand Down Expand Up @@ -390,4 +390,49 @@ public function getCalendar(int $userId): array

return $newValues;
}

/**
* Generates an event array for fullcalendar.io frontend.
*
* @param string $title
* @param bool $allDay
* @param int $id
* @param int $projectId
* @param string $eventType
* @param string $dateContext
* @param string $backgroundColor
* @param string $borderColor
* @param int|null $dateFrom
* @param int|null $dateTo
*
* @return array
*/
private function mapEventData(
string $title,
string $description,
bool $allDay,
int $id,
int $projectId,
string $eventType,
string $dateContext,
string $backgroundColor,
string $borderColor,
string $dateFrom,
string $dateTo
): array {
return array(
'title' => $title,
'allDay' => $allDay,
'description' => $description,
'dateFrom' => $dateFrom,
'dateTo' => $dateTo,
'id' => $id,
'projectId' => $projectId,
'eventType' => $eventType,
'dateContext' => $dateContext,
'backgroundColor' => $backgroundColor,
'borderColor' => $borderColor,
'url' => BASE_URL . "/dashboard/home/#/tickets/showTicket/" . $id,
);
}
}
35 changes: 0 additions & 35 deletions app/Domain/Comments/Hx-controllers/DeleteComment.php

This file was deleted.

12 changes: 0 additions & 12 deletions app/Domain/Connector/Models/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,28 @@
*/
class Integration
{
#[DbColumn(type: "int")]
public int $id;

#[DbColumn(type: "varchar")]
public ?string $providerId;

#[DbColumn(type: "varchar")]
public ?string $method;

#[DbColumn(type: "varchar")]
public ?string $entity;

#[DbColumn(type: "text")]
public ?string $fields;

#[DbColumn(type: "text")]
public ?string $schedule;

#[DbColumn(type: "text")]
public ?string $notes;

#[DbColumn(type: "text")]
public ?string $auth;

#[DbColumn(type: "text")]
public ?string $meta;

#[DbColumn(type: "datetime")]
public ?string $createdOn;

#[DbColumn(type: "int")]
public ?string $createdBy;

#[DbColumn(type: "datetime")]
public ?string $lastSync;


Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Connector/Services/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private function parseMilestones($fields, $values)
}
} else {
$id = $_SESSION['userdata']['id'];
foreach ($this->values as &$row) {
foreach ($values as &$row) {
$row['editorId'] = $id;
}
}
Expand Down
26 changes: 26 additions & 0 deletions app/Domain/CsvImport/Listeners/AddCSVImportProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Leantime\Domain\CsvImport\Listeners;

use Leantime\Domain\CsvImport\Services;

/**
* Class AddCSVImportProvider
*
* The AddCSVImportProvider class is responsible for adding a CSV import provider to the given payload.
*/
class AddCSVImportProvider
{
/**
* @param mixed $payload
* @return mixed
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle(mixed $payload): mixed
{
$provider = app()->make(Services\CsvImport::class);
$payload[$provider->id] = $provider;

return $payload;
}
}
29 changes: 2 additions & 27 deletions app/Domain/CsvImport/register.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
<?php

namespace CsvImport;

use CsvImport\Services\CsvImport as CsvImportService;
use Leantime\Core\Events;

/**
* MotivationalQuotes
*
* Register Events here
*
*/
//Create function for the event
class AddCSVImportProvider
{
/**
* @param $payload
* @return mixed
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle($payload): mixed
{
$provider = app()->make(CsvImportService::class);
$payload[$provider->id] = $provider;

return $payload;
}
}
use Leantime\Domain\CsvImport\Listeners\AddCSVImportProvider;

//Register event listener
Events::add_filter_listener(
"domain.connector.services.providers.loadProviders.providerList",
new addCSVImportProvider()
new AddCSVImportProvider()
);
2 changes: 1 addition & 1 deletion app/Domain/Dashboard/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function init(
$this->settingRepo = $settingRepo;
$this->calendarRepo = $calendarRepo;
$this->reactionsService = $reactionsService;
$this->reportsService = $reportsService;
$this->reportService = $reportsService;
$this->widgetService = $widgetService;

$_SESSION['lastPage'] = BASE_URL . "/dashboard/home";
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Dashboard/Templates/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class="btn pull-right margin-right {{ $isFavorite ? 'isFavorite' : ''}} tw-mr-[5
@endif

<a href="#/tickets/showTicket/{{ $row['id'] }}">
{!! sprintf("<strong>%s</strong>", $row['headline']) !!}
<strong>{{ $row['headline'] }}</strong>
</a>

@include("tickets::partials.ticketsubmenu", ["ticket" => $row,"onTheClock" => $tpl->get("onTheClock")])
Expand Down
Loading

0 comments on commit 7e4c255

Please sign in to comment.