DEV: Улучшение по codacy.com

This commit is contained in:
Evg 2023-01-10 07:18:34 +03:00
parent 4e885d9614
commit 1a7ddfbeee
18 changed files with 50 additions and 55 deletions

View File

@ -23,7 +23,7 @@ class DefaultTask extends \Hleb\Scheme\App\Commands\MainTask
/**
* @param string|int|null $arg - argument description
*/
protected function execute($arg = null)
protected function execute()
{
// Your code here.

View File

@ -116,8 +116,6 @@ class EditFacetController extends Controller
public function pages()
{
$facet_id = Request::getInt('id');
$facet = FacetPresence::index(Request::getInt('id'), 'id', 'blog');
// Доступ получает только автор и админ

View File

@ -25,7 +25,7 @@ class EditPostController extends Controller
// Форма редактирования post
public function index()
{
$post = PostPresence::index($post_id = Request::getInt('id'), 'id');
$post = PostPresence::index(Request::getInt('id'), 'id');
$post_related = [];
if ($post['post_related']) {

View File

@ -51,19 +51,6 @@ class PostController extends Controller
// Get replies and comments on the post
$answers = $this->answersPost($content['post_id'], $content['post_feature'], $sorting = Request::getGet('sort'));
$content_img = config('meta.img_path');
if ($content['post_content_img']) {
$content_img = Img::PATH['posts_cover'] . $content['post_content_img'];
} elseif ($content['post_thumb_img']) {
$content_img = Img::PATH['posts_thumb'] . $content['post_thumb_img'];
}
$description = fragment($content['post_content'], 250);
if ($description == '') {
$description = strip_tags($content['post_title']);
}
$description = (fragment($content['post_content'], 250) == '') ? strip_tags($content['post_title']) : fragment($content['post_content'], 250);
if ($content['post_is_deleted'] == 1) {
@ -87,7 +74,7 @@ class PostController extends Controller
'published_time' => $content['post_date'],
'type' => 'article',
'og' => true,
'imgurl' => $content_img,
'imgurl' => self::images($content),
'url' => post_slug($content['post_id'], $content['post_slug']),
];
@ -240,6 +227,21 @@ class PostController extends Controller
);
}
// Define an image for meta tags
// Определим изображение для meta- тегов
public static function images($content)
{
$content_img = config('meta.img_path');
if ($content['post_content_img']) {
$content_img = Img::PATH['posts_cover'] . $content['post_content_img'];
} elseif ($content['post_thumb_img']) {
$content_img = Img::PATH['posts_thumb'] . $content['post_thumb_img'];
}
return $content_img;
}
// Last 5 pages by content id
// Последние 5 страниц по id контенту
public function last($content_id)

View File

@ -224,5 +224,4 @@ class Html
{
return '<button type="submit" name="action" class="btn btn-primary" value="submit">' . $text . '</button>';
}
}

View File

@ -131,13 +131,13 @@ class AnswerModel extends \Hleb\Scheme\App\Models\MainModel
// Getting answers in a post
// Получаем ответы в посте
public static function getAnswersPost($post_id, $type, $sorting = 'new')
{
{
$user_id = UserData::getUserId();
if ($type == 1) {
$sorting = 'top';
$sorting = 'top';
}
switch ($sorting) {
case 'top':
$sort = 'ORDER BY answer_lo DESC, answer_votes DESC';
@ -145,12 +145,12 @@ class AnswerModel extends \Hleb\Scheme\App\Models\MainModel
case 'old':
$sort = 'ORDER BY answer_id DESC';
break;
// new
// new
default:
$sort = '';
break;
}
// TODO: Сгруппировать комментарии по ответу (избавимся N+1)
// LEFT JOIN comments ON comment_answer_id = answer_id
// comment_answer_id,

View File

@ -7,7 +7,7 @@ namespace App\Services;
use Hleb\Constructor\Handlers\Request;
use App\Services\Сheck\PostPresence;
use App\Services\Сheck\AnswerPresence;
use App\Models\{AnswerModel, PostModel};
use App\Models\AnswerModel;
use UserData, Access;
class AnswerBest extends Base
@ -17,8 +17,8 @@ class AnswerBest extends Base
public function __construct()
{
$this->user = UserData::get();
}
}
public function index()
{
// Get the answer data (for which the "best answer" is selected)
@ -28,12 +28,12 @@ class AnswerBest extends Base
// Get the data of the post that has this answer
// Получим данные поста в котором есть этот ответ
$post = PostPresence::index($answer['answer_post_id'], 'id');
// Let's check the access. Only the staff and the author of the post can choose the best answer (without regard to time)
// Проверим доступ. Только персонал и автор поста может выбирать лучший ответ (без учета времени)
if (Access::author('post', $post, 0) == false) {
return false;
}
}
// If the number of answers is less than 2, then we will not let you choose the best answer
// Если количество ответов меньше 2, то не дадим выбирать лучший ответ
@ -46,7 +46,7 @@ class AnswerBest extends Base
AnswerModel::setBest($post['post_id'], $answer['answer_id'], $post['post_lo']);
return true;
}
// Если Лучшего ответа нет, то первичная запись
AnswerModel::setBest($post['post_id'], $answer['answer_id'], false);
return true;

View File

@ -6,7 +6,7 @@ namespace App\Services;
use Hleb\Constructor\Handlers\Request;
use App\Services\Сheck\PostPresence;
use App\Models\{ActionModel, AuditModel, NotificationModel, PostModel};
use App\Models\{ActionModel, AuditModel, NotificationModel};
use UserData, Msg;
class Audit extends Base
@ -37,7 +37,7 @@ class Audit extends Base
$url = post_slug($post['post_id'], $post['post_slug']) . '#' . $type_id;
$this->create($content_type, $content_id, $url, 'report');
return true;
}
@ -130,7 +130,7 @@ class Audit extends Base
public function create(string $type, int $last_content_id, string $url, string $type_notification = 'audit')
{
$action_type = ($type_notification == 'audit') ? NotificationModel::TYPE_AUDIT : NotificationModel::TYPE_REPORT;
AuditModel::add(
[
'action_type' => $type,

View File

@ -17,5 +17,4 @@ class Ignored extends Base
return __('app.successfully');
}
}

View File

@ -13,10 +13,8 @@ class Telegram
$token = config('integration.telegram_token');
$chat_id = config('integration.chat_id');
$txt = rawurlencode($title);
// file_get_contents($url . '/bot'. $token .'/sendMessage?chat_id='. $chat_id .'&disable_notification=true&parse_mode=HTML&text=' . $txt);
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}", "r");
}
fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}", "r");
}
}

View File

@ -12,7 +12,7 @@ class Yandex
$code = Request::getPost('code');
if (!empty($code)) {
$sending_url = 'https://oauth.yandex.ru/token'; // отправка
$receiving_url = 'https://login.yandex.ru/info'; // получение

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Services\Сheck;
use App\Models\FacetModel;
use UserData;
class FacetPresence
{

View File

@ -11,11 +11,11 @@ trait Author
if (!$user_new) {
return $user_id;
}
if (UserData::checkAdmin()) {
$answer_user_new = json_decode($user_new, true);
return $answer_user_new[0]['id'];
}
return $user_id;
}
}
}

View File

@ -21,4 +21,4 @@ trait LastDataModified
header('Last-Modified: ' . gmdate("D, d M Y H:i:s \G\M\T", $lastModified));
}
}
}

View File

@ -17,6 +17,6 @@ trait Related
}
return implode(',', $id ?? []);
}
return false;
return false;
}
}
}

View File

@ -13,4 +13,4 @@ trait Slug
return substr($uri, 0, 90);
}
}
}

View File

@ -22,7 +22,7 @@ trait Views
}
return true;
}
public function setProfileView($user_id)
{
if (!isset($_SESSION['usernumbers'])) {
@ -35,4 +35,4 @@ trait Views
}
return true;
}
}
}

View File

@ -30,11 +30,11 @@ function url(string $key = null, array $params = [])
}
function post_slug(int $id, string $slug = '')
{
{
if (config('meta.slug_post') == false) {
return hleb_get_by_name('post_id', ['id' => $id]);
}
return hleb_get_by_name('post', ['id' => $id, 'slug' => $slug]);
}
@ -60,10 +60,10 @@ function is_current($url)
{
$uri = Request::getUri();
if ($url == $uri) return true;
$a = explode('?', $uri);
$a = explode('?', $uri);
if ($url == $a[0]) return true;
return false;
}