style(ecs): add easy-coding-standard to enforce coding style rules for php

- update .devcontainer settings: remove auto-formatting
for php + set intelephense as default formatter
- remove prettier php plugin as it lacks php 8 support
- add captain hook action for checking style pre-commit
- fix style with ecs on all files except views
This commit is contained in:
Yassine Doghri 2021-05-19 16:35:13 +00:00
commit aa1612342e
No known key found for this signature in database
GPG key ID: 3E7F89498B960C9F
230 changed files with 3420 additions and 5884 deletions

View file

@ -1,8 +1,7 @@
<?php
/**
* Class SoundbiteModel
* Model for podcasts_soundbites table in database
* Class SoundbiteModel Model for podcasts_soundbites table in database
*
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -11,8 +10,8 @@
namespace App\Models;
use CodeIgniter\Database\BaseResult;
use App\Entities\Soundbite;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Model;
class SoundbiteModel extends Model
@ -21,6 +20,7 @@ class SoundbiteModel extends Model
* @var string
*/
protected $table = 'soundbites';
/**
* @var string
*/
@ -43,6 +43,7 @@ class SoundbiteModel extends Model
* @var string
*/
protected $returnType = Soundbite::class;
/**
* @var bool
*/
@ -57,16 +58,18 @@ class SoundbiteModel extends Model
* @var string[]
*/
protected $afterInsert = ['clearCache'];
/**
* @var string[]
*/
protected $afterUpdate = ['clearCache'];
/**
* @var string[]
*/
protected $beforeDelete = ['clearCache'];
public function deleteSoundbite(int $podcastId, int $episodeId, int $soundbiteId): BaseResult|bool
public function deleteSoundbite(int $podcastId, int $episodeId, int $soundbiteId): BaseResult | bool
{
return $this->delete([
'podcast_id' => $podcastId,
@ -83,14 +86,15 @@ class SoundbiteModel extends Model
public function getEpisodeSoundbites(int $podcastId, int $episodeId): array
{
$cacheName = "podcast#{$podcastId}_episode#{$episodeId}_soundbites";
if (!($found = cache($cacheName))) {
if (! ($found = cache($cacheName))) {
$found = $this->where([
'episode_id' => $episodeId,
'podcast_id' => $podcastId,
])
->orderBy('start_time')
->findAll();
cache()->save($cacheName, $found, DECADE);
cache()
->save($cacheName, $found, DECADE);
}
return $found;
}
@ -107,16 +111,15 @@ class SoundbiteModel extends Model
: $data['id']['episode_id'],
);
cache()->delete(
"podcast#{$episode->podcast_id}_episode#{$episode->id}_soundbites",
);
cache()
->delete("podcast#{$episode->podcast_id}_episode#{$episode->id}_soundbites",);
// delete cache for rss feed
cache()->deleteMatching("podcast#{$episode->podcast_id}_feed*");
cache()
->deleteMatching("podcast#{$episode->podcast_id}_feed*");
cache()->deleteMatching(
"page_podcast#{$episode->podcast_id}_episode#{$episode->id}_*",
);
cache()
->deleteMatching("page_podcast#{$episode->podcast_id}_episode#{$episode->id}_*",);
return $data;
}