Showing 205 of 290 total issues
Function setupListeners
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
setupListeners() {
// Filter tab click
onSelect(this.filterTabs, e => {
this.resetAll();
this.filter = e.target.dataset.filter;
File PageContent.php
has 261 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace BookStack\Entities\Tools;
use BookStack\Entities\Models\Page;
Function isSortChangePermissible
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected function isSortChangePermissible(BookSortMapItem $sortMapItem, BookChild $model, ?Entity $currentParent, ?Entity $newBook, ?Entity $newChapter): bool
{
// Stop if we can't see the current parent or new book.
if (!$currentParent || !$newBook) {
return false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parsePlural
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
parsePlural(translation, count, replacements) {
const splitText = translation.split('|');
const exactCountRegex = /^{([0-9]+)}/;
const rangeRegex = /^\[([0-9]+),([0-9*]+)]/;
let result = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File TrashCan.php
has 251 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace BookStack\Entities\Tools;
use BookStack\Entities\EntityProvider;
Consider simplifying this complex logical expression. Open
if ($model instanceof Page) {
$parentPermission = ($currentParent instanceof Chapter) ? 'chapter-update' : 'book-update';
$hasCurrentParentPermission = userCan($parentPermission, $currentParent);
// This needs to check if there was an intended chapter location in the original sort map
Method processAccessTokenCallback
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function processAccessTokenCallback(OidcAccessToken $accessToken, OidcProviderSettings $settings): User
{
$idTokenText = $accessToken->getIdToken();
$idToken = new OidcIdToken(
$idTokenText,
Function init
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
export async function init(editor) {
const Code = await window.importVersioned('code');
/**
* @param {ViewUpdate} v
Method build
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function build(): array
{
// Note, while we attempt to use the user's preference here, the request to the manifest
// does not start a session, so we won't have current user context.
// This was attempted but removed since manifest calls could affect user session
Function register
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function register(editor) {
// Headers
for (let i = 1; i < 5; i++) {
editor.shortcuts.add(`meta+${i}`, '', ['FormatBlock', false, `h${i + 1}`]);
}
Method index
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function index(Request $request)
{
$this->checkPermission('settings-manage');
$this->checkPermission('users-manage');
Function show
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
show(event = null) {
this.hideAll();
this.menu.style.display = 'block';
this.menu.classList.add('anim', 'menuIn');
Function containHtml
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
protected function containHtml(string $htmlContent): string
{
$imageTagsOutput = [];
preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\").*?\>/i", $htmlContent, $imageTagsOutput);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function drop
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
function drop(editor, options, event) {
const {dom} = editor;
const rng = window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(
event.clientX,
event.clientY,
Method handle
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handle(Connection $db): int
{
$oldUrl = str_replace("'", '', $this->argument('oldUrl'));
$newUrl = str_replace("'", '', $this->argument('newUrl'));
Function register
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
function register(editor) {
editor.addCommand('drawio', () => {
const selectedNode = editor.selection.getNode();
showDrawingEditor(editor, isDrawing(selectedNode) ? selectedNode : null);
});
Function setup
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
setup() {
// Options
this.draftsEnabled = this.$opts.draftsEnabled === 'true';
this.editorType = this.$opts.editorType;
this.pageId = Number(this.$opts.pageId);
Function updateContent
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function updateContent(pngData) {
const loadingImage = window.baseUrl('/loading.gif');
const handleUploadError = error => {
if (error.status === 413) {
Function processUsers
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function processUsers(array $users, UserAvatars $userAvatar): int
{
$dryRun = !$this->option('force');
$this->info(count($users) . " user(s) found to update avatars for.");
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function run()
{
// Create an editor user
$editorUser = User::factory()->create();
$editorRole = Role::getRole('editor');