Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added phpstan #20

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests PHPStan in environments

on: [pull_request]

jobs:
php82-laravel-latest-phpstan-postgres:
runs-on: ubuntu-latest
container:
image: escolalms/php:8.2

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
TZ: Europe/Warsaw
ports:
- 5432:5432

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp env/postgres/* .

- name: Update composer
run: COMPOSER_ROOT_VERSION=0.9.9 composer update

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: vendor/bin/phpstan analyse
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ jobs:
- name: Instantiate package
uses: actions/checkout@v2

- name: Update composer
run: composer update

- name: Setup environment
run: cp env/postgres/* .

- name: Update composer
run: composer update

- name: Clear config
run: vendor/bin/testbench config:clear

Expand Down Expand Up @@ -107,12 +107,12 @@ jobs:
- name: Instantiate package
uses: actions/checkout@v2

- name: Update composer
run: composer update

- name: Setup environment
run: cp env/postgres/* .

- name: Update composer
run: composer update

- name: Clear config
run: vendor/bin/testbench config:clear

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"escolalms/consultations": "^0",
"escolalms/courses": "^0.4",
"escolalms/cart": "^0",
"orchestra/testbench": "^5.0|^6.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": ">=5.0",
"phpunit/phpunit": "^9.0",
"nunomaduro/larastan": "^2.0"
},
"license": "MIT",
"authors": [
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon

parameters:

paths:
- src/

# The level 9 is the highest level
level: 6
3 changes: 3 additions & 0 deletions src/Consultations/ApprovedTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class ApprovedTermVariables extends CommonConsultationVariables
{
/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Consultations/ApprovedTermWithTrainerVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class ApprovedTermWithTrainerVariables extends CommonConsultationVariables
{
/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
16 changes: 16 additions & 0 deletions src/Consultations/CommonConsultationVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ abstract class CommonConsultationVariables extends SmsVariables
const VAR_CONSULTATION_TITLE = '@VarConsultationTitle';
const VAR_CONSULTATION_PROPOSED_TERM = '@VarConsultationProposedTerm';

/**
* @return array<string, mixed>
*/
public static function mockedVariables(?User $user = null): array
{
$faker = \Faker\Factory::create();
Expand All @@ -23,17 +26,27 @@ public static function mockedVariables(?User $user = null): array
]);
}

/**
* @return array<string, mixed>
*/
public static function variablesFromEvent(EventWrapper $event): array
{
return array_merge(parent::variablesFromEvent($event), [
// @phpstan-ignore-next-line
self::VAR_USER_NAME => $event->getUser()->name,
// @phpstan-ignore-next-line
self::VAR_CONSULTATION_TITLE => $event->getConsultationTerm()->consultation->name,
// @phpstan-ignore-next-line
self::VAR_CONSULTATION_PROPOSED_TERM => Carbon::make($event->getConsultationTerm()->executed_at)
// @phpstan-ignore-next-line
->setTimezone($event->getUser()->current_timezone)
->format('Y-m-d H:i:s'),
]);
}

/**
* @return string[]
*/
public static function requiredVariables(): array
{
return [
Expand All @@ -43,6 +56,9 @@ public static function requiredVariables(): array
];
}

/**
* @return string[]
*/
public static function requiredVariablesInSection(string $sectionKey): array
{
if ($sectionKey === 'content') {
Expand Down
3 changes: 3 additions & 0 deletions src/Consultations/RejectTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class RejectTermVariables extends CommonConsultationVariables
{
/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Consultations/RejectTermWithTrainerVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class RejectTermWithTrainerVariables extends CommonConsultationVariables
{
/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Consultations/ReminderAboutTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class ReminderAboutTermVariables extends CommonConsultationVariables
{
/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
13 changes: 13 additions & 0 deletions src/Consultations/ReminderTrainerAboutTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ class ReminderTrainerAboutTermVariables extends CommonConsultationVariables
{
const VAR_CONSULTATION_USER_NAME = '@VarConsultationUserName';

/**
* @return string[]
*/
public static function requiredVariables(): array
{
return array_merge(parent::requiredVariables(), [
self::VAR_CONSULTATION_USER_NAME,
]);
}

/**
* @return string[]
*/
public static function requiredVariablesInSection(string $sectionKey): array
{
if ($sectionKey === 'content') {
Expand All @@ -25,13 +31,20 @@ public static function requiredVariablesInSection(string $sectionKey): array
return [];
}

/**
* @return array<string, mixed>
*/
public static function variablesFromEvent(EventWrapper $event): array
{
return array_merge(parent::variablesFromEvent($event), [
// @phpstan-ignore-next-line
self::VAR_CONSULTATION_USER_NAME => $event->getConsultationTerm()->user->name,
]);
}

/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
13 changes: 13 additions & 0 deletions src/Consultations/ReportTermVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ class ReportTermVariables extends CommonConsultationVariables
{
const VAR_CONSULTATION_BUYER_NAME = '@VarConsultationBuyerName';

/**
* @return string[]
*/
public static function requiredVariables(): array
{
return array_merge(parent::requiredVariables(), [
self::VAR_CONSULTATION_BUYER_NAME,
]);
}

/**
* @return string[]
*/
public static function requiredVariablesInSection(string $sectionKey): array
{
if ($sectionKey === 'content') {
Expand All @@ -25,13 +31,20 @@ public static function requiredVariablesInSection(string $sectionKey): array
return [];
}

/**
* @return array<string, mixed>
*/
public static function variablesFromEvent(EventWrapper $event): array
{
return array_merge(parent::variablesFromEvent($event), [
// @phpstan-ignore-next-line
self::VAR_CONSULTATION_BUYER_NAME => $event->getConsultationTerm()->user->name,
]);
}

/**
* @return array<string, mixed>
*/
public static function defaultSectionsContent(): array
{
return [
Expand Down
16 changes: 15 additions & 1 deletion src/Core/SmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

class SmsChannel extends AbstractTemplateChannelClass implements TemplateChannelContract
{
/**
* @param array<string, mixed> $sections
*/
public static function send(EventWrapper $event, array $sections): bool
{
$user = $event->user();
Expand All @@ -31,26 +34,37 @@ public static function send(EventWrapper $event, array $sections): bool
return self::sendMessage($user, $sections);
}

/**
* @param array<string, mixed> $sections
*/
public static function preview(User $user, array $sections): bool
{
return self::sendMessage($user, $sections);
}

/**
* @return Collection<int, TemplateSectionSchema>
*/
public static function sections(): Collection
{
return new Collection([
// @phpstan-ignore-next-line
new TemplateSectionSchema('content', TemplateSectionTypeEnum::SECTION_TEXT(), true),
]);
}

/**
* @param array<string, mixed> $sections
*/
private static function sendMessage(User $user, array $sections): bool
{
// @phpstan-ignore-next-line
if (!$user->phone) {
return false;
}

try {
Sms::send($sections['content'])->to($user->phone)->dispatch();
Sms::send($sections['content'])->to($user->phone)->dispatch();
} catch (\Exception $exception) {
Log::error('[' . __CLASS__ . '] ' . $exception->getMessage());
return false;
Expand Down
9 changes: 9 additions & 0 deletions src/Core/SmsVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@

abstract class SmsVariables extends AbstractTemplateVariableClass implements TemplateVariableContract
{
/**
* @return array<string, mixed>
*/
public static function mockedVariables(?User $user = null): array
{
return [];
}

/**
* @return array<string, mixed>
*/
public static function variablesFromEvent(EventWrapper $event): array
{
return [];
}

/**
* @return string[]
*/
public static function requiredSections(): array
{
return [];
Expand Down
Loading
Loading