Skip to content

Commit

Permalink
fix: fix phpstan issues (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 25, 2020
1 parent 0493004 commit 5e28296
Show file tree
Hide file tree
Showing 79 changed files with 345 additions and 368 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ jobs:
run: |
cp tests/.env.ci-${{ matrix.connection }} .env
touch config/version
echo '{"/js/app.js": "/js/app.js", "/css/app.css": "/css/app.css"}' > public/mix-manifest.json
mkdir -p public/js
echo '' > public/js/app.js
mkdir -p public/css
echo '' > public/css/app.css
- name: Create SQLite database
if: matrix.connection == 'sqlite'
run: |
Expand Down
56 changes: 28 additions & 28 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,36 @@ jobs:
# run: vendor/bin/psalm --output-format=github


# phpstan:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php-version: [7.4]
phpstan:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.4]

# steps:
# - name: Checkout sources
# uses: actions/checkout@v2
steps:
- name: Checkout sources
uses: actions/checkout@v2

# - name: Setup PHP ${{ matrix.php-version }}
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php-version }}
# coverage: none
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none

# - name: Get Composer Cache Directory
# id: composer-cache
# run: echo "::set-output name=dir::$(composer config cache-files-dir)"
# - name: Cache composer files
# uses: actions/cache@v2
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# ${{ runner.os }}-composer-
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer files
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-composer-
# - name: Install dependencies
# run: composer install --no-progress --no-interaction --no-suggest --prefer-dist --optimize-autoloader
- name: Install dependencies
run: composer install --no-progress --no-interaction --no-suggest --prefer-dist --optimize-autoloader

# - name: Run phpstan
# run: vendor/bin/phpstan analyse
- name: Run phpstan
run: vendor/bin/phpstan analyse
20 changes: 10 additions & 10 deletions app/Console/Commands/Helpers/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use RuntimeException;
use Tests\Helpers\CommandCallerFake;

/**
* @method static void exec(\Illuminate\Console\Command $command, string $message, string $commandline)
* @method static void artisan(\Illuminate\Console\Command $command, string $message, string $commandline, array $arguments)
*/
class Command
{
/**
Expand All @@ -22,9 +26,9 @@ public static function fake() : CommandCallerContract
/**
* The Command Executor.
*
* @var CommandCallerContract
* @var CommandCallerContract|null
*/
private static $CommandCaller;
private static $commandCaller;

/**
* Get the current backend command.
Expand All @@ -33,11 +37,11 @@ public static function fake() : CommandCallerContract
*/
private static function getBackend() : CommandCallerContract
{
if (is_null(static::$CommandCaller)) {
static::$CommandCaller = app(CommandCaller::class); // @codeCoverageIgnore
if (! static::$commandCaller) {
static::$commandCaller = app(CommandCaller::class); // @codeCoverageIgnore
}

return static::$CommandCaller;
return static::$commandCaller;
}

/**
Expand All @@ -47,7 +51,7 @@ private static function getBackend() : CommandCallerContract
*/
public static function setBackend(CommandCallerContract $executor) : void
{
static::$CommandCaller = $executor;
static::$commandCaller = $executor;
}

/**
Expand All @@ -63,10 +67,6 @@ public static function __callStatic($method, $args)
{
$instance = static::getBackend();

if (! $instance) {
throw new RuntimeException('No backend.'); // @codeCoverageIgnore
}

return $instance->$method(...$args);
}
}
9 changes: 0 additions & 9 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,4 @@ public function render($request, Throwable $e)

return parent::render($request, $e);
}

protected function whoopsHandler()
{
try {
return app(\Whoops\Handler\HandlerInterface::class);
} catch (\Illuminate\Contracts\Container\BindingResolutionException $e) {
return parent::whoopsHandler();
}
}
}
2 changes: 1 addition & 1 deletion app/Helpers/BirthdayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function isBirthdayInXDays(Carbon $startDate, Carbon $birthdate, i
/**
* Check if the birthdate will happen in the given range.
*
* @param Carbon $startDate
* @param Carbon $birthdate
* @param Carbon $minDate
* @param Carbon $maxDate
* @return bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function store(Request $request, int $companyId): JsonResponse
*
* @param Request $request
* @param int $companyId
* @param mixed $expenseCategoryId
* @param int $expenseCategoryId
* @return JsonResponse
*/
public function update(Request $request, int $companyId, int $expenseCategoryId): JsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function team(Request $request, int $companyId, int $questionId, int $tea
->orderBy('answers.created_at', 'desc')
->paginate(10);

$answersCollection = CompanyQuestionViewHelper::allAnswers($question, $answers, $employee);
$answersCollection = CompanyQuestionViewHelper::question($question, $answers, $employee);

return Inertia::render('Company/Question/Show', [
'teams' => $teams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function index(): Response
$employeeInformation = [
'id' => $employee->id,
'dashboard_view' => 'expenses',
'is_manager' => $employee->directReports->count() > 0 ? true : false,
'is_manager' => $employee->directReports->count() > 0,
'can_manage_expenses' => $employee->can_manage_expenses,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function index(): Response
'has_logged_morale_today' => $employee->hasAlreadyLoggedMoraleToday(),
'dashboard_view' => 'me',
'can_manage_expenses' => $employee->can_manage_expenses,
'is_manager' => $employee->directReports->count() > 0 ? true : false,
'is_manager' => $employee->directReports->count() > 0,
'has_worked_from_home_today' => WorkFromHomeHelper::hasWorkedFromHomeOnDate($employee, Carbon::now()),
'question' => DashboardMeViewHelper::question($employee),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function index(Request $request, int $companyId, int $teamId = null, $req
'has_logged_morale_today' => $employee->hasAlreadyLoggedMoraleToday(),
'dashboard_view' => 'team',
'can_manage_expenses' => $employee->can_manage_expenses,
'is_manager' => $employee->directReports->count() > 0 ? true : false,
'is_manager' => $employee->directReports->count() > 0,
];

UpdateDashboardPreference::dispatch([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Inertia\Inertia;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Helpers\InstanceHelper;
use App\Helpers\PaginatorHelper;
use App\Models\Company\Employee;
use Illuminate\Routing\Redirector;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\RedirectResponse;
use App\Http\ViewHelpers\Employee\EmployeeLogViewHelper;
use Illuminate\Database\Eloquent\ModelNotFoundException;

Expand All @@ -21,7 +24,7 @@ class EmployeeLogsController extends Controller
* @param Request $request
* @param int $companyId
* @param int $employeeId
* @return Response
* @return Redirector|RedirectResponse|Response
*/
public function index(Request $request, int $companyId, int $employeeId)
{
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Company/Project/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ public function destroyLink(Request $request, int $companyId, int $projectId, in
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $linkId
*/
public function createStatus(Request $request, int $companyId, int $projectId)
{
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Company/Team/TeamMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function index(Request $request, int $companyId, int $teamId): JsonRespon
}

$search = $request->input('searchTerm');

/** @var \Illuminate\Pagination\LengthAwarePaginator */
$potentialEmployees = Employee::search(
$search,
$companyId,
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Authenticate extends Middleware
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
return $request->expectsJson() ? route('login') : null;
}
}
2 changes: 1 addition & 1 deletion app/Http/ViewHelpers/Adminland/AdminEmployeeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static function getCollectionOfEmployees(Collection $employees, Company
'permission_level' => $employee->permission_level,
'avatar' => $employee->avatar,
'invitation_link' => $employee->invitation_link,
'invited' => ! $employee->invitation_used_at && $employee->invitation_link ? true : false,
'invited' => (bool) (! $employee->invitation_used_at && $employee->invitation_link),
'lock_status' => $employee->locked,
'url_view' => route('employees.show', [
'company' => $company,
Expand Down
53 changes: 3 additions & 50 deletions app/Http/ViewHelpers/Company/CompanyQuestionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\ViewHelpers\Company;

use App\Helpers\DateHelper;
use App\Models\Company\Team;
use App\Models\Company\Answer;
use App\Helpers\QuestionHelper;
use App\Models\Company\Company;
Expand Down Expand Up @@ -77,8 +76,8 @@ public static function question(Question $question, $answers, Employee $employee
'id' => $answer->answer_id,
'body' => $answer->body,
'employee' => [
'name' => $answer->employee->name,
'avatar' => $answer->employee->avatar,
'name' => $answer->employee ? $answer->employee->name : $answer->name,
'avatar' => $answer->employee ? $answer->employee->avatar : $answer->avatar,
],
]);
}
Expand All @@ -88,7 +87,7 @@ public static function question(Question $question, $answers, Employee $employee
'title' => $question->title,
'number_of_answers' => $answers->count(),
'answers' => $answerCollection,
'employee_has_answered' => $detailOfAnswer ? true : false,
'employee_has_answered' => (bool) $detailOfAnswer,
'answer_by_employee' => $detailOfAnswer,
'date' => $date,
'url' => route('company.questions.show', [
Expand Down Expand Up @@ -120,52 +119,6 @@ public static function teams(Collection $teams): Collection
return $teamsCollection;
}

/**
* Detail of a question, along with all the answers only written by
* employees in a team.
*
* @param Question $question
* @param mixed $answers
* @param Employee $employee
*
* @return array|null
*/
public static function allAnswers(Question $question, $answers, Employee $employee): ?array
{
$answerByEmployee = QuestionHelper::getAnswer($question, $employee);

$date = self::getInformationAboutActivationDate($question);

// preparing the array of answers
$answerCollection = collect([]);
foreach ($answers as $answer) {
$answerCollection->push([
'id' => $answer->answer_id,
'body' => $answer->body,
'employee' => [
'name' => $answer->name,
'avatar' => $answer->avatar,
],
]);
}

$array = [
'id' => $question->id,
'title' => $question->title,
'number_of_answers' => $answers->count(),
'answers' => $answerCollection,
'employee_has_answered' => $answerByEmployee ? true : false,
'answer_by_employee' => $answerByEmployee,
'date' => $date,
'url' => route('company.questions.show', [
'company' => $employee->company,
'question' => $question,
]),
];

return $array;
}

/**
* @param Question $question
* @return string|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function expense(Expense $expense): array
* @param Collection $directReports
* @return SupportCollection|null
*/
public static function oneOnOnes(Employee $manager, Collection $directReports): SupportCollection
public static function oneOnOnes(Employee $manager, Collection $directReports): ?SupportCollection
{
// get the list of employees this manager manages
$oneOnOnesCollection = collect([]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/ViewHelpers/Dashboard/DashboardMeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function question(Employee $employee): ?array
'title' => $question->title,
'number_of_answers' => $allAnswers->count(),
'answers' => $answersCollection,
'employee_has_answered' => $answerByEmployee ? true : false,
'employee_has_answered' => (bool) $answerByEmployee,
'answer_by_employee' => $answerByEmployee ? [
'body' => $answerByEmployee->body,
] : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function stats(Collection $entries): array
/**
* Array containing all the one on ones done.
*
* @param Collection $expenses
* @param Collection $oneOnOnes
* @param Employee $employee
* @return SupportCollection
*/
Expand Down
Loading

0 comments on commit 5e28296

Please sign in to comment.