1
0
Fork 0
mirror of https://gitnet.fr/deblan/side_menu.git synced 2025-12-18 05:10:50 +01:00

add constructor property promotion

add return type of methods
This commit is contained in:
Simon Vieille 2024-06-27 20:27:31 +02:00
parent 05c35b9a63
commit 7c5654f3bc
No known key found for this signature in database
GPG key ID: 579388D585F70417
14 changed files with 78 additions and 388 deletions

View file

@ -22,37 +22,25 @@ use OCA\SideMenu\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
class AdminSettingController extends Controller
{
/**
* @var IConfig
*/
protected $config;
/**
* @var IURLGenerator
*/
protected $urlGenerator;
public function __construct($appName, IRequest $request, IConfig $config, IURLGenerator $urlGenerator)
{
public function __construct(
$appName,
IRequest $request,
protected IConfig $config,
protected IURLGenerator $urlGenerator
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->urlGenerator = $urlGenerator;
}
/**
* @NoCSRFRequired
*
* @return RedirectResponse
*/
public function removeCache()
public function removeCache(): RedirectResponse
{
$this->config->setAppValue(Application::APP_ID, 'cache-categories', '[]');
@ -63,10 +51,8 @@ class AdminSettingController extends Controller
/**
* @NoCSRFRequired
*
* @return Response
*/
public function exportConfiguration()
public function exportConfiguration(): DataDownloadResponse
{
$keys = $this->config->getAppKeys(Application::APP_ID);
$appConfig = [];

View file

@ -29,28 +29,14 @@ use OCP\IUserSession;
class AppController extends Controller
{
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var AppRepository
*/
protected $appRepository;
public function __construct(
string $appName,
IRequest $request,
AppRepository $appRepository,
IURLGenerator $urlGenerator,
ConfigProxy $config
protected AppRepository $appRepository,
protected IURLGenerator $urlGenerator,
protected ConfigProxy $config
) {
parent::__construct($appName, $request);
$this->appRepository = $appRepository;
$this->urlGenerator = $urlGenerator;
$this->config = $config;
}
/**

View file

@ -32,49 +32,26 @@ use OCP\IUserSession;
class CssController extends Controller
{
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var User
*/
protected $user;
/**
* @var ThemingDefaults
*/
protected $theming;
/**
* @var Color
*/
protected $color;
protected ?User $user;
public function __construct(
string $appName,
IRequest $request,
ConfigProxy $config,
ThemingDefaults $theming,
Color $color
protected ConfigProxy $config,
protected ThemingDefaults $theming,
protected Color $color
) {
parent::__construct($appName, $request);
$this->user = OC::$server[IUserSession::class]->getUser();
$this->config = $config;
$this->theming = $theming;
$this->color = $color;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*
* @return Response
*/
public function stylesheet()
public function stylesheet(): TemplateResponse
{
$response = new TemplateResponse(Application::APP_ID, 'css/stylesheet', $this->getConfig(), 'blank');
$response->addHeader('Content-Type', 'text/css');
@ -107,15 +84,15 @@ class CssController extends Controller
$isDarkThemeUserEnabled = 'dark' === $this->config->getUserValue($this->user, 'theme', '', 'accessibility');
$isBreezeDarkUserEnabled = $this->config->getUserValue($this->user, 'theme_enabled', '', 'breezedark');
$isBreezeDarkUserEnabled = '1' === $isBreezeDarkUserEnabled ||
($isBreezeDarkGlobalEnabled && '' === $isBreezeDarkUserEnabled);
$isBreezeDarkUserEnabled = '1' === $isBreezeDarkUserEnabled
|| ($isBreezeDarkGlobalEnabled && '' === $isBreezeDarkUserEnabled);
} else {
$isDarkThemeUserEnabled = false;
$isBreezeDarkUserEnabled = false;
}
$isDarkMode = ($isAccessibilityAppEnabled && $isDarkThemeUserEnabled) ||
($isBreezeDarkAppEnabled && $isBreezeDarkUserEnabled);
$isDarkMode = ($isAccessibilityAppEnabled && $isDarkThemeUserEnabled)
|| ($isBreezeDarkAppEnabled && $isBreezeDarkUserEnabled);
$primaryColor = $this->theming->getColorPrimary();
$lightenPrimaryColor = $this->color->adjustBrightness($primaryColor, 0.2);

View file

@ -32,32 +32,14 @@ use OCP\L10N\IFactory;
class JsController extends Controller
{
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var User
*/
protected $user;
/**
* @var ThemingDefaults
*/
protected $themingDefaults;
/**
* @var IFactory
*/
protected $l10nFactory;
protected ?User $user;
public function __construct(
string $appName,
IRequest $request,
ConfigProxy $config,
ThemingDefaults $themingDefaults,
IFactory $l10nFactory
protected ConfigProxy $config,
protected ThemingDefaults $themingDefaults,
protected IFactory $l10nFactory
) {
parent::__construct($appName, $request);

View file

@ -19,7 +19,6 @@
namespace OCA\SideMenu\Controller;
use OC;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\URLGenerator;
use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\CategoryRepository;
@ -32,57 +31,24 @@ use OCP\L10N\IFactory;
class NavController extends Controller
{
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var AppRepository
*/
protected $appRepository;
/**
* @var IFactory
*/
protected $l10nFactory;
/**
* @var CategoryFetcher
*/
protected $categoryFetcher;
/**
* @var URLGenerator
*/
protected $router;
public function __construct(
string $appName,
IRequest $request,
ConfigProxy $config,
AppRepository $appRepository,
CategoryRepository $categoryRepository,
URLGenerator $router,
IFactory $l10nFactory
protected ConfigProxy $config,
protected AppRepository $appRepository,
protected CategoryRepository $categoryRepository,
protected URLGenerator $router,
protected IFactory $l10nFactory
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->appRepository = $appRepository;
$this->categoryRepository = $categoryRepository;
$this->l10nFactory = $l10nFactory;
$this->router = $router;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*
* @return JSONResponse
*/
public function items()
public function items(): JSONResponse
{
$user = OC::$server[IUserSession::class]->getUser();
$items = [];
@ -189,11 +155,11 @@ class NavController extends Controller
usort($items, function ($a, $b) use ($categoriesLabels) {
foreach ($categoriesLabels as $key => $value) {
if ($a['categoryId'] === 'other') {
if ('other' === $a['categoryId']) {
return -1;
}
if ($b['categoryId'] === 'other') {
if ('other' === $b['categoryId']) {
return 1;
}

View file

@ -21,40 +21,20 @@ namespace OCA\SideMenu\Controller;
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\ConfigProxy;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
class PersonalSettingController extends Controller
{
/**
* @var IConfig
*/
protected $config;
/**
* @var ConfigProxy
*/
protected $configProxy;
/**
* @var IUserSession
*/
protected $userSession;
public function __construct(
$appName,
IRequest $request,
IConfig $config,
ConfigProxy $configProxy,
IUserSession $userSession
protected IConfig $config,
protected ConfigProxy $configProxy,
protected IUserSession $userSession
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->configProxy = $configProxy;
$this->userSession = $userSession;
}
/**
@ -63,10 +43,8 @@ class PersonalSettingController extends Controller
*
* @param mixed $name
* @param mixed $value
*
* @return Response
*/
public function valueSet($name, $value)
public function valueSet($name, $value): array
{
$doSave = false;
$user = $this->userSession->getUser();

View file

@ -3,13 +3,13 @@
namespace OCA\SideMenu\Service;
use OC\User\User;
use OCP\INavigationManager;
use OCP\L10N\IFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\IUserSession;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\SideMenu\AppInfo\Application;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\INavigationManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
/**
* class AppRepository.
@ -35,10 +35,8 @@ class AppRepository
/**
* Retrieves visibles apps.
*
* @return array
*/
public function getVisibleApps()
public function getVisibleApps(): array
{
$navigation = $this->navigationManager->getAll();
$appCategoriesCustom = $this->config->getAppValueArray('apps-categories-custom', '[]');
@ -99,7 +97,7 @@ class AppRepository
return $visibleApps;
}
public function getAppName($app)
public function getAppName($app): string
{
return $this->config->getAppValue(
'app.navigation.name',
@ -108,7 +106,7 @@ class AppRepository
);
}
public function getOrderedApps(?User $user = null)
public function getOrderedApps(?User $user = null): array
{
$apps = $this->getVisibleApps();
$orders = $this->config->getAppValueArray('apps-order', '[]');

View file

@ -15,51 +15,19 @@ use OCP\L10N\IFactory;
*/
class CategoryRepository
{
/**
* @var CategoryFetcher
*/
protected $categoryFetcher;
/**
* @var IFactory
*/
protected $l10nFactory;
/**
* @var ConfigProxy
*/
protected $config;
/**
* @var IConfig
*/
protected $iConfig;
/**
* @var IUserSession
*/
protected $userSession;
public function __construct(
CategoryFetcher $categoryFetcher,
ConfigProxy $config,
IConfig $iConfig,
IFactory $l10nFactory,
IUserSession $userSession
protected CategoryFetcher $categoryFetcher,
protected ConfigProxy $config,
protected IConfig $iConfig,
protected IFactory $l10nFactory,
protected IUserSession $userSession
) {
$this->categoryFetcher = $categoryFetcher;
$this->l10nFactory = $l10nFactory;
$this->config = $config;
$this->iConfig = $iConfig;
$this->userSession = $userSession;
}
/**
* Retrieves categories.
*
* @return array
*/
public function getOrderedCategories()
public function getOrderedCategories(): array
{
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
$type = $this->config->getAppValue('categories-order-type', 'default');

View file

@ -13,12 +13,7 @@ use OCP\IConfig;
*/
class ConfigProxy
{
/**
* @var IConfig
*/
protected $config;
public function __construct(IConfig $config)
public function __construct(protected IConfig $config)
{
$this->config = $config;
}

View file

@ -11,12 +11,7 @@ use OCP\IDBConnection;
*/
class LangRepository
{
/**
* @var IDBConnection
*/
protected $db;
public function __construct(IDBConnection $db)
public function __construct(protected IDBConnection $db)
{
$this->db = $db;
}

View file

@ -21,75 +21,27 @@ namespace OCA\SideMenu\Settings;
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\CategoryRepository;
use OCA\SideMenu\Service\Color;
use OCA\SideMenu\Service\ConfigProxy;
use OCA\SideMenu\Service\LangRepository;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Settings\ISettings;
use OCA\Theming\ThemingDefaults;
use OCA\SideMenu\Service\Color;
use OCA\SideMenu\Service\LangRepository;
class Admin implements ISettings
{
/**
* @var IL10N
*/
private $l;
/**
* @var ILogger
*/
private $logger;
/**
* @var ConfigProxy
*/
private $config;
/**
* @var AppRepository
*/
private $appRepository;
/**
* @var CategoryRepository
*/
private $categoryRepository;
/**
* @var ThemingDefaults
*/
protected $theming;
/**
* @var Color
*/
protected $color;
/**
* @var LangRepository
*/
protected $langRepository;
public function __construct(
IL10N $l,
ILogger $logger,
ConfigProxy $config,
AppRepository $appRepository,
CategoryRepository $categoryRepository,
ThemingDefaults $theming,
Color $color,
LangRepository $langRepository
protected IL10N $l,
protected ILogger $logger,
protected ConfigProxy $config,
protected AppRepository $appRepository,
protected CategoryRepository $categoryRepository,
protected ThemingDefaults $theming,
protected Color $color,
protected LangRepository $langRepository
) {
$this->l = $l;
$this->logger = $logger;
$this->config = $config;
$this->appRepository = $appRepository;
$this->categoryRepository = $categoryRepository;
$this->theming = $theming;
$this->color = $color;
$this->langRepository = $langRepository;
}
/**

View file

@ -25,51 +25,22 @@ use OCP\Settings\IIconSection;
class AdminSection implements IIconSection
{
/**
* @var IL10N
*/
private $l;
/**
* @var IURLGenerator
*/
private $url;
public function __construct(IURLGenerator $url, IL10N $l)
{
$this->url = $url;
$this->l = $l;
public function __construct(
protected IURLGenerator $url,
protected IL10N $l
) {
}
/**
* returns the ID of the section. It is supposed to be a lower case string,
* e.g. 'ldap'.
*
* @returns string
*/
public function getID()
{
return Application::APP_ID;
}
/**
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*
* @return string
*/
public function getName()
{
return $this->l->t(Application::APP_NAME);
}
/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*
* E.g.: 70
*/
public function getPriority()
{
return 70;

View file

@ -29,43 +29,13 @@ use OCP\Settings\ISettings;
class Personal implements ISettings
{
/**
* @var IL10N
*/
private $l;
/**
* @var ILogger
*/
private $logger;
/**
* @var ConfigProxy
*/
private $config;
/**
* @var IUserSession
*/
private $userSession;
/**
* @var AppRepository
*/
private $appRepository;
public function __construct(
IL10N $l,
ILogger $logger,
ConfigProxy $config,
IUserSession $userSession,
AppRepository $appRepository
protected IL10N $l,
protected ILogger $logger,
protected ConfigProxy $config,
protected IUserSession $userSession,
protected AppRepository $appRepository
) {
$this->l = $l;
$this->logger = $logger;
$this->config = $config;
$this->userSession = $userSession;
$this->appRepository = $appRepository;
}
/**

View file

@ -26,34 +26,13 @@ use OCP\Settings\IIconSection;
class PersonalSection implements IIconSection
{
/**
* @var IL10N
*/
private $l;
/**
* @var IURLGenerator
*/
private $url;
/**
* @var ConfigProxy
*/
private $configProxy;
public function __construct(IURLGenerator $url, IL10N $l, ConfigProxy $configProxy)
{
$this->url = $url;
$this->l = $l;
$this->configProxy = $configProxy;
public function __construct(
protected IURLGenerator $url,
protected IL10N $l,
protected ConfigProxy $configProxy
) {
}
/**
* returns the ID of the section. It is supposed to be a lower case string,
* e.g. 'ldap'.
*
* @returns string
*/
public function getID()
{
if ($this->configProxy->getAppValueBool('force', '0')) {
@ -63,12 +42,6 @@ class PersonalSection implements IIconSection
return Application::APP_ID;
}
/**
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*
* @return string
*/
public function getName()
{
if ($this->configProxy->getAppValueBool('force', '0')) {
@ -78,13 +51,6 @@ class PersonalSection implements IIconSection
return $this->l->t(Application::APP_NAME);
}
/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*
* E.g.: 70
*/
public function getPriority()
{
if ($this->configProxy->getAppValueBool('force', '0')) {