refactor: add rector to enforce type declarations, code quality + style and remove dead code

- update CI process to include quality stage (tests + code review)
- add captainhook to install git pre-commit & pre-push hooks
- remove .devcontainer Dockerfile to use project's docker-compose services: all
services can now be started automatically using vscode
- update docs/setup-development.md
This commit is contained in:
Yassine Doghri 2021-05-06 14:00:48 +00:00
commit 5c5c6da4be
No known key found for this signature in database
GPG key ID: 3E7F89498B960C9F
302 changed files with 9802 additions and 4674 deletions

View file

@ -8,6 +8,11 @@
namespace ActivityPub\Controllers;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Exceptions\PageNotFoundException;
use ActivityPub\Entities\Note;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use ActivityPub\Config\ActivityPub;
use ActivityPub\Objects\OrderedCollectionObject;
use ActivityPub\Objects\OrderedCollectionPage;
@ -16,15 +21,18 @@ use CodeIgniter\I18n\Time;
class NoteController extends Controller
{
/**
* @var string[]
*/
protected $helpers = ['activitypub'];
/**
* @var \ActivityPub\Entities\Note|null
* @var Note|null
*/
protected $note;
/**
* @var \ActivityPub\Config\ActivityPub
* @var ActivityPub
*/
protected $config;
@ -36,14 +44,14 @@ class NoteController extends Controller
public function _remap($method, ...$params)
{
if (!($this->note = model('NoteModel')->getNoteById($params[0]))) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
throw PageNotFoundException::forPageNotFound();
}
unset($params[0]);
return $this->$method(...$params);
}
public function index()
public function index(): RedirectResponse
{
$noteObjectClass = $this->config->noteObject;
$noteObject = new $noteObjectClass($this->note);
@ -53,7 +61,7 @@ class NoteController extends Controller
->setBody($noteObject->toJSON());
}
public function replies()
public function replies(): RedirectResponse
{
// get note replies
$noteReplies = model('NoteModel')
@ -84,7 +92,7 @@ class NoteController extends Controller
$noteObjectClass = $this->config->noteObject;
foreach ($paginatedReplies as $reply) {
$replyObject = new $noteObjectClass($reply);
array_push($orderedItems, $replyObject->toJSON());
$orderedItems[] = $replyObject->toJSON();
}
$collection = new OrderedCollectionPage($pager, $orderedItems);
}
@ -108,7 +116,7 @@ class NoteController extends Controller
->with('errors', $this->validator->getErrors());
}
$newNote = new \ActivityPub\Entities\Note([
$newNote = new Note([
'actor_id' => $this->request->getPost('actor_id'),
'message' => $this->request->getPost('message'),
'published_at' => Time::now(),
@ -119,7 +127,7 @@ class NoteController extends Controller
->back()
->withInput()
// TODO: translate
->with('error', 'Couldn\'t create Note');
->with('error', "Couldn't create Note");
}
// Note without preview card has been successfully created
@ -184,7 +192,7 @@ class NoteController extends Controller
->with('errors', $this->validator->getErrors());
}
$newReplyNote = new \ActivityPub\Entities\Note([
$newReplyNote = new Note([
'actor_id' => $this->request->getPost('actor_id'),
'in_reply_to_id' => $this->note->id,
'message' => $this->request->getPost('message'),
@ -196,14 +204,17 @@ class NoteController extends Controller
->back()
->withInput()
// TODO: translate
->with('error', 'Couldn\'t create Reply');
->with('error', "Couldn't create Reply");
}
// Reply note without preview card has been successfully created
return redirect()->back();
}
public function attemptRemoteAction($action)
/**
* @return mixed|ResponseInterface
*/
public function attemptRemoteAction(string $action)
{
$rules = [
'handle' =>
@ -228,7 +239,7 @@ class NoteController extends Controller
$data = get_webfinger_data($username, $domain);
}
} catch (\CodeIgniter\HTTP\Exceptions\HTTPException $e) {
} catch (HTTPException $httpException) {
return redirect()
->back()
->withInput()