Skip to content

Commit

Permalink
Merge pull request #32076 from frederic34/phpstan_doc_ui
Browse files Browse the repository at this point in the history
fix phpstan doc ui
  • Loading branch information
eldy authored Dec 24, 2024
2 parents ac08dc3 + ff71e12 commit a478bf9
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 203 deletions.
42 changes: 42 additions & 0 deletions build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,48 @@ parameters:
count: 2
path: ../../htdocs/admin/tools/purge.php

-
message: '#^Method Documentation\:\:displayMenu\(\) has parameter \$menu with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Method Documentation\:\:displaySummary\(\) has parameter \$menu with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Method Documentation\:\:setMenu\(\) should return mixed but return statement is missing\.$#'
identifier: return.missing
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Method Documentation\:\:showCode\(\) has parameter \$lines with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Property Documentation\:\:\$menu type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Property Documentation\:\:\$summary type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Property Documentation\:\:\$view type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../htdocs/admin/tools/ui/class/documentation.class.php

-
message: '#^Variable \$massactionbutton in empty\(\) always exists and is always falsy\.$#'
identifier: empty.variable
Expand Down
26 changes: 15 additions & 11 deletions htdocs/admin/tools/ui/class/documentation.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -57,6 +58,7 @@ class Documentation
* Constructor
*
* @param DoliDB $db Database handler
* @return void
*/
public function __construct(DoliDB $db)
{
Expand All @@ -75,7 +77,6 @@ public function __construct(DoliDB $db)
*/
private function setMenu()
{

global $hookmanager;


Expand Down Expand Up @@ -223,7 +224,8 @@ public function docFooter()
}

/**
* Output sidebar
* Output sidebar
*
* @return void
*/
public function showSidebar()
Expand Down Expand Up @@ -312,14 +314,16 @@ public function showBreadcrumb()
}

/**
* Output summary
* Output summary
*
* @param int $showsubmenu Show Sub menus: 0 = No, 1 = Yes
* @param int $showsubmenu_summary Show summary of sub menus: 0 = No, 1 = Yes
* @return void
*/
public function showSummary($showsubmenu = 1, $showsubmenu_summary = 1)
{
$i = 0;
$menu_entry = [];
if (!empty($this->view)) :
// On se place au bon niveau
foreach ($this->view as $view) {
Expand Down Expand Up @@ -384,16 +388,16 @@ public function displaySummary($menu, $level = 0, $showsubmenu = 1, $showsubmenu
* Output a View Code area
*
* @param array $lines Lines of code to show
* @param string $option Source code language ('html', 'php' etc)
* @return void
*/
public function showCode($lines = array())
public function showCode($lines = array(), $option = 'html')
{
print '<div class="documentation-code"><pre>';
if (!empty($lines)) {
foreach ($lines as $lineofcode) {
print dol_htmlentities($lineofcode).'<br/>';
}
}
print '</pre></div>';
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
print '<div class="documentation-code">';
$content = implode("\n", $lines) . "\n";
$doleditor = new DolEditor(md5($content), $content, '', 0, 'Basic', 'In', true, false, 'ace', 0, '99%', 1);
print $doleditor->Create(1, '', false, '', $option);
print '</div>';
}
}
48 changes: 28 additions & 20 deletions htdocs/admin/tools/ui/components/badges.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
<?php
/*
* Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program and files/directory inner it is free software: you can
* redistribute it and/or modify it under the terms of the
* GNU Affero General Public License (AGPL) as published by
* the Free Software Foundation, either version 3 of the License, or
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AGPL for more details.
* GNU General Public License for more details.
*
* You should have received a copy of the GNU AGPL
* along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

$res=0;
if (! $res && file_exists("../../main.inc.php")) : $res=@include '../../main.inc.php';
endif;
if (! $res && file_exists("../../../main.inc.php")) : $res=@include '../../../main.inc.php';
endif;
if (! $res && file_exists("../../../../main.inc.php")) : $res=@include '../../../../main.inc.php';
endif;
// Load Dolibarr environment
require '../../../../main.inc.php';

/**
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/

// Protection if external user
if ($user->socid > 0) : accessforbidden();
endif;
if ($user->socid > 0) {
accessforbidden();
}

// Includes
dol_include_once('admin/tools/ui/class/documentation.class.php');
require_once DOL_DOCUMENT_ROOT . '/admin/tools/ui/class/documentation.class.php';

// Load documentation translations
$langs->load('uxdocumentation');

//
$documentation = new Documentation($db);

$morejs = [
'/includes/ace/src/ace.js',
'/includes/ace/src/ext-statusbar.js',
'/includes/ace/src/ext-language_tools.js',
];
// Output html head + body - Param is Title
$documentation->docHeader('Badges');
$documentation->docHeader('Badges', $morejs);

// Set view for menu and breadcrumb
// Menu must be set in constructor of documentation class
Expand All @@ -49,7 +57,7 @@
$documentation->showSidebar(); ?>

<div class="doc-wrapper">

<?php $documentation->showBreadCrumb(); ?>

<div class="doc-content-wrapper">
Expand Down Expand Up @@ -310,4 +318,4 @@
<?php
// Output close body + html
$documentation->docFooter();
?>
?>
Loading

0 comments on commit a478bf9

Please sign in to comment.