Skip to content

Commit

Permalink
added a pre-commit hook for the team
Browse files Browse the repository at this point in the history
  • Loading branch information
kayleb01 committed Oct 31, 2021
1 parent 630fffe commit e367190
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 12 deletions.
25 changes: 16 additions & 9 deletions app/Services/TaskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Services;

use Carbon\Carbon;
use App\Helpers\Sort;
use App\Helpers\Response;
use Illuminate\Support\Str;
use App\Helpers\Collaborator;
use App\Services\TodoService;
use App\Repositories\TaskRepository;
//use App\Services\ServiceTrait;

class TaskService extends TaskRepository
{
Expand Down Expand Up @@ -112,9 +113,9 @@ public function getLatestTask()
public function toggleStatus($id)
{
$task = $this->todoService->find($id); // Get the Task

// Set new date if it is null or empty, else set back to empty
$archived = array_key_exists('archived_at', $task)
&& $task['archived_at'] ? '' : Carbon::now(); // Set new date if it is null or empty, else set back to empty
&& $task['archived_at'] ? '' : Carbon::now();

// prepare the payload
$data = array();
Expand Down Expand Up @@ -147,7 +148,7 @@ public function taskCollection($request)

$sort = $request->order;
if ($sort) {
$allTasks = collect($allTasks->sortBy('created_at'))->toArray;
$allTasks = collect($allTasks->sortBy('created_at'))->toArray;
}

$time = time();
Expand All @@ -157,7 +158,6 @@ public function taskCollection($request)
$end_date = $value['end_date'];
$convert_date = strtotime($end_date);
if ($convert_date >= $time) {

$arr = $value;
}
}
Expand Down Expand Up @@ -196,10 +196,14 @@ public function markTask($request, $todoId)
// Send Mail
$user_ids = Collaborator::listAllUsersInTodo($todo);
$collab = new Collaborator;
$collab->sendMails($user_ids, 'Task Added', 'A task with the title' . $request->title . 'has been marked in the todo');
$collab->sendMails(
$user_ids,
'Task Added',
'A task with the title' . $request->title . 'has been marked in the todo'
);
return $todoWithId;
} else {
abort(500, $result);
abort(500, $result);
}
}

Expand Down Expand Up @@ -227,14 +231,17 @@ public function add($request, $todoId)
$result = $this->todoService->update($todo, $todoId);

if (isset($result['modified_documents']) && $result['modified_documents'] > 0) {

// Publish To Centrifugo
$todoWithId = array_merge(['_id' => $todoId], $todo);
$this->publishToRoomChannel($todo['channel'], $todoWithId, "Task", "create");
// Send Mail
$user_ids = Collaborator::listAllUsersInTodo($todo);
$collab = new Collaborator;
$collab->sendMails($user_ids, 'Task Added', 'A task with the title'.$request->title.'has been added to the todo');
$collab->sendMails(
$user_ids,
'Task Added',
'A task with the title'.$request->title.'has been added to the todo'
);

return $todoWithId;
}
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^9.3.3",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
124 changes: 122 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# get bash colors and styles here:
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
C_RESET='\e[0m'
C_RED='\e[31m'
C_GREEN='\e[32m'
C_YELLOW='\e[33m'

function __run() #(step, name, cmd)
{
local color output exitcode

printf "${C_YELLOW}[%s]${C_RESET} %-20s" "$1" "$2"
output=$(eval "$3" 2>&1)
exitcode=$?

if [[ 0 == $exitcode || 130 == $exitcode ]]; then
echo -e "${C_GREEN}OK!${C_RESET}"
else
echo -e "${C_RED}NOK!${C_RESET}\n\n$output"
exit 1
fi
}

modified="git diff --diff-filter=M --name-only --cached | grep \".php$\""
ignore="resources/lang,resources/views,bootstrap/helpers,database/migrations,bin"
phpcs="vendor/bin/phpcs --report=code --colors --report-width=80 --standard=PSR2 --ignore=${ignore}"

__run "1/3" "php lint" "${modified} | xargs -r php -l"
__run "2/3" "code sniffer" "${modified} | xargs -r ${phpcs}"
__run "3/3" "phpstan" "${modified} | xargs -r vendor/bin/phpstan analyse"

0 comments on commit e367190

Please sign in to comment.