diff --git a/docs/appendix/upgrade-notes/5.x-to-6.0.rst b/docs/appendix/upgrade-notes/5.x-to-6.0.rst index 5bbed8eb69f..274cf4aea57 100644 --- a/docs/appendix/upgrade-notes/5.x-to-6.0.rst +++ b/docs/appendix/upgrade-notes/5.x-to-6.0.rst @@ -104,6 +104,8 @@ Removed lib functions * ``elgg_disable_annotations()`` has been removed * ``elgg_enable_annotations()`` has been removed * ``elgg_set_view_location()`` has been removed +* ``elgg_strrchr()`` has been removed +* ``elgg_strripos()`` has been removed * ``elgg_unrequire_css()`` has been removed. Use ``elgg_unregister_external_file('css', $view)`` as replacement. Removed class functions diff --git a/engine/classes/Elgg/Cli.php b/engine/classes/Elgg/Cli.php index 47afaf76d8e..b74e350efd6 100644 --- a/engine/classes/Elgg/Cli.php +++ b/engine/classes/Elgg/Cli.php @@ -22,21 +22,6 @@ class Cli { */ protected $console; - /** - * @var EventsService - */ - protected $events; - - /** - * @var InputInterface - */ - protected $input; - - /** - * @var OutputInterface - */ - protected $output; - /** * Constructor * @@ -45,18 +30,14 @@ class Cli { * @param OutputInterface $output Console output */ public function __construct( - EventsService $events, - InputInterface $input, - OutputInterface $output + protected EventsService $events, + protected InputInterface $input, + protected OutputInterface $output ) { - $console = new \Elgg\Cli\Application('Elgg', elgg_get_release()); $console->setup($input, $output); $this->console = $console; - $this->events = $events; - $this->input = $input; - $this->output = $output; } /** @@ -64,7 +45,7 @@ public function __construct( * * @return void */ - protected function bootstrap() { + protected function bootstrap(): void { $commands = array_merge($this->getCoreCommands(), $this->getPluginCommands()); $commands = $this->events->triggerResults('commands', 'cli', [], $commands); @@ -78,7 +59,7 @@ protected function bootstrap() { * * @return array */ - protected function getCoreCommands() { + protected function getCoreCommands(): array { $conf = \Elgg\Project\Paths::elgg() . 'engine/cli_commands.php'; return \Elgg\Includer::includeFile($conf); } @@ -88,7 +69,7 @@ protected function getCoreCommands() { * * @return array */ - protected function getPluginCommands() { + protected function getPluginCommands(): array { $return = []; $plugins = elgg_get_plugins('active'); @@ -112,7 +93,7 @@ protected function getPluginCommands() { * * @return void */ - public function add($command) { + public function add(string $command): void { if (!class_exists($command)) { return; } @@ -150,7 +131,7 @@ public function add($command) { * * @return void */ - public function run(bool $bootstrap = true) { + public function run(bool $bootstrap = true): void { if ($bootstrap) { $this->bootstrap(); } @@ -163,7 +144,7 @@ public function run(bool $bootstrap = true) { * * @return InputInterface */ - public function getInput() { + public function getInput(): InputInterface { return $this->input; } @@ -172,7 +153,7 @@ public function getInput() { * * @return OutputInterface */ - public function getOutput() { + public function getOutput(): OutputInterface { return $this->output; } } diff --git a/engine/classes/Elgg/EmailService.php b/engine/classes/Elgg/EmailService.php index 0d2f26aee46..ab1cf831e07 100644 --- a/engine/classes/Elgg/EmailService.php +++ b/engine/classes/Elgg/EmailService.php @@ -28,41 +28,6 @@ class EmailService { use Loggable; - /** - * @var Config - */ - protected $config; - - /** - * @var EventsService - */ - protected $events; - - /** - * @var TransportInterface - */ - protected $mailer; - - /** - * @var HtmlFormatter - */ - protected $html_formatter; - - /** - * @var ImageFetcherService - */ - protected $image_fetcher; - - /** - * @var ViewsService - */ - protected $views; - - /** - * @var CssCompiler - */ - protected $css_compiler; - /** * Constructor * @@ -75,21 +40,14 @@ class EmailService { * @param CssCompiler $css_compiler Css compiler */ public function __construct( - Config $config, - EventsService $events, - TransportInterface $mailer, - HtmlFormatter $html_formatter, - ViewsService $views, - ImageFetcherService $image_fetcher, - CssCompiler $css_compiler - ) { - $this->config = $config; - $this->events = $events; - $this->mailer = $mailer; - $this->html_formatter = $html_formatter; - $this->views = $views; - $this->image_fetcher = $image_fetcher; - $this->css_compiler = $css_compiler; + protected Config $config, + protected EventsService $events, + protected TransportInterface $mailer, + protected HtmlFormatter $html_formatter, + protected ViewsService $views, + protected ImageFetcherService $image_fetcher, + protected CssCompiler $css_compiler + ) { } /** @@ -100,7 +58,7 @@ public function __construct( * @return bool * @throws RuntimeException */ - public function send(Email $email) { + public function send(Email $email): bool { $email = $this->events->triggerResults('prepare', 'system:email', [], $email); if (!$email instanceof Email) { $msg = "'prepare','system:email' event handlers should return an instance of " . Email::class; @@ -123,8 +81,7 @@ public function send(Email $email) { * @return bool * @throws RuntimeException */ - public function transport(Email $email) { - + public function transport(Email $email): bool { if ($this->events->triggerResults('transport', 'system:email', ['email' => $email], false)) { return true; } diff --git a/engine/classes/Elgg/Event.php b/engine/classes/Elgg/Event.php index 262e37cc8ac..b82c7fbb80a 100644 --- a/engine/classes/Elgg/Event.php +++ b/engine/classes/Elgg/Event.php @@ -10,31 +10,6 @@ */ class Event { - /** - * @var PublicContainer - */ - protected $dic; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $type; - - /** - * @var mixed - */ - protected $value; - - /** - * @var mixed - */ - protected $params; - /** * Constructor * @@ -44,12 +19,13 @@ class Event { * @param mixed $value Event value * @param mixed $params Event params */ - public function __construct(PublicContainer $dic, string $name, string $type, $value = null, $params = []) { - $this->dic = $dic; - $this->name = $name; - $this->type = $type; - $this->value = $value; - $this->params = $params; + public function __construct( + protected PublicContainer $dic, + protected string $name, + protected string $type, + protected $value = null, + protected $params = [] + ) { } /** diff --git a/engine/classes/Elgg/Filesystem/File.php b/engine/classes/Elgg/Filesystem/File.php index 808b2940e14..5f759ed6de4 100644 --- a/engine/classes/Elgg/Filesystem/File.php +++ b/engine/classes/Elgg/Filesystem/File.php @@ -10,34 +10,26 @@ */ class File { - /** @var Directory */ - private $directory; - - /** @var string */ - private $path; - /** * Constructor * * @param Directory $directory The directory where this file resides * @param string $path The path to this file relative to the directory */ - public function __construct(Directory $directory, $path) { - $this->directory = $directory; - $this->path = $path; + public function __construct(protected Directory $directory, protected string $path) { } /** * @return boolean Whether this file exists. */ - public function exists() { + public function exists(): bool { return $this->directory->isFile($this->path); } /** * @return string The file's basename. */ - public function getBasename() { + public function getBasename(): string { return pathinfo($this->path, PATHINFO_BASENAME); } @@ -46,7 +38,7 @@ public function getBasename() { * * @return string */ - public function getContents() { + public function getContents(): string { return $this->directory->getContents($this->path); } @@ -56,21 +48,21 @@ public function getContents() { * @param string $content File content * @return void */ - public function putContents($content) { + public function putContents($content): void { $this->directory->putContents($this->path, $content); } /** * @return string The file's extension. */ - public function getExtension() { + public function getExtension(): string { return pathinfo($this->path, PATHINFO_EXTENSION); } /** * @return string The full path to this file. */ - public function getPath() { + public function getPath(): string { return $this->directory->getPath($this->path); } diff --git a/engine/classes/Elgg/Forms/StickyForms.php b/engine/classes/Elgg/Forms/StickyForms.php index 8fbd65b0149..47775453c16 100644 --- a/engine/classes/Elgg/Forms/StickyForms.php +++ b/engine/classes/Elgg/Forms/StickyForms.php @@ -9,19 +9,13 @@ * @internal */ class StickyForms { - - /** - * @var \ElggSession - */ - protected $session; - + /** * Constructor * * @param \ElggSession $session Session for storage */ - public function __construct(\ElggSession $session) { - $this->session = $session; + public function __construct(protected \ElggSession $session) { } /** diff --git a/engine/classes/Elgg/Gatekeeper.php b/engine/classes/Elgg/Gatekeeper.php index bc77209eaa9..23040aebc3e 100644 --- a/engine/classes/Elgg/Gatekeeper.php +++ b/engine/classes/Elgg/Gatekeeper.php @@ -23,36 +23,6 @@ */ class Gatekeeper { - /** - * @var SessionManagerService - */ - protected $session_manager; - - /** - * @var \Elgg\Http\Request - */ - protected $request; - - /** - * @var RedirectService - */ - protected $redirects; - - /** - * @var EntityTable - */ - protected $entities; - - /** - * @var AccessCollections - */ - protected $access; - - /** - * @var Translator - */ - protected $translator; - /** * Constructor * @@ -64,27 +34,22 @@ class Gatekeeper { * @param Translator $translator Translator */ public function __construct( - SessionManagerService $session_manager, - HttpRequest $request, - RedirectService $redirects, - EntityTable $entities, - AccessCollections $access, - Translator $translator + protected SessionManagerService $session_manager, + protected HttpRequest $request, + protected RedirectService $redirects, + protected EntityTable $entities, + protected AccessCollections $access, + protected Translator $translator ) { - $this->session_manager = $session_manager; - $this->request = $request; - $this->redirects = $redirects; - $this->entities = $entities; - $this->access = $access; - $this->translator = $translator; } /** * Require a user to be authenticated to with code execution + * * @return void * @throws LoggedInGatekeeperException */ - public function assertAuthenticatedUser() { + public function assertAuthenticatedUser(): void { if ($this->session_manager->isLoggedIn()) { return; } @@ -96,10 +61,11 @@ public function assertAuthenticatedUser() { /** * Require a user to be not authenticated (logged out) to with code execution + * * @return void * @throws LoggedOutGatekeeperException */ - public function assertUnauthenticatedUser() { + public function assertUnauthenticatedUser(): void { if (!$this->session_manager->isLoggedIn()) { return; } @@ -112,11 +78,12 @@ public function assertUnauthenticatedUser() { /** * Require an admin user to be authenticated to proceed with code execution + * * @return void * @throws GatekeeperException * @throws AdminGatekeeperException */ - public function assertAuthenticatedAdmin() { + public function assertAuthenticatedAdmin(): void { $this->assertAuthenticatedUser(); $user = $this->session_manager->getLoggedInUser(); @@ -307,7 +274,7 @@ public function assertAccessibleGroup(\ElggGroup $group, \ElggUser $user = null) * @return void * @throws AjaxGatekeeperException */ - public function assertXmlHttpRequest() { + public function assertXmlHttpRequest(): void { if ($this->request->isXmlHttpRequest()) { return; } diff --git a/engine/classes/Elgg/Groups/Tool.php b/engine/classes/Elgg/Groups/Tool.php index cacd7608979..731fe8dab5a 100644 --- a/engine/classes/Elgg/Groups/Tool.php +++ b/engine/classes/Elgg/Groups/Tool.php @@ -14,15 +14,7 @@ */ class Tool implements CollectionItemInterface { - /** - * @var string - */ - public $name; - - /** - * @var array - */ - protected $options; + protected array $options; /** * Constructor @@ -30,9 +22,7 @@ class Tool implements CollectionItemInterface { * @param string $name Tool name * @param array $options Tool options */ - public function __construct($name, array $options = []) { - $this->name = $name; - + public function __construct(public string $name, array $options = []) { $defaults = [ 'label' => null, 'default_on' => true, @@ -83,7 +73,7 @@ public function getPriority() { * * @return string */ - public function getLabel() { + public function getLabel(): string { $label = elgg_extract('label', $this->options); if (isset($label)) { return $label; @@ -108,9 +98,10 @@ public function getDescription(): ?string { /** * Is the tool enabled by default? + * * @return bool */ - public function isEnabledByDefault() { + public function isEnabledByDefault(): bool { $default_on = elgg_extract('default_on', $this->options, true); if ($default_on === true || $default_on === 'yes') { @@ -122,9 +113,10 @@ public function isEnabledByDefault() { /** * Get metadata name for DB storage + * * @return string */ - public function mapMetadataName() { + public function mapMetadataName(): string { return "{$this->name}_enable"; } @@ -136,7 +128,7 @@ public function mapMetadataName() { * * @return string */ - public function mapMetadataValue($value = null) { + public function mapMetadataValue($value = null): string { if (!isset($value)) { $value = $this->default_on; } diff --git a/engine/classes/Elgg/Http/WebAppManifestResource.php b/engine/classes/Elgg/Http/WebAppManifestResource.php index ea59c15e755..d42d52dd1a4 100644 --- a/engine/classes/Elgg/Http/WebAppManifestResource.php +++ b/engine/classes/Elgg/Http/WebAppManifestResource.php @@ -13,17 +13,13 @@ * @internal */ class WebAppManifestResource { - - /** @var \ElggSite */ - private $site; - + /** * Constructor * * @param \ElggSite $site The site serving this manifest. */ - public function __construct(\ElggSite $site) { - $this->site = $site; + public function __construct(protected \ElggSite $site) { } /** @@ -31,7 +27,7 @@ public function __construct(\ElggSite $site) { * * @return array */ - public function get() { + public function get(): array { return [ 'display' => 'standalone', 'name' => $this->site->getDisplayName(), diff --git a/engine/classes/Elgg/I18n/Locale.php b/engine/classes/Elgg/I18n/Locale.php index 508abb001b9..fe57fa563e0 100644 --- a/engine/classes/Elgg/I18n/Locale.php +++ b/engine/classes/Elgg/I18n/Locale.php @@ -11,17 +11,13 @@ * @internal */ final class Locale { - - /** @var string */ - private $locale; - + /** * Use Locale::parse to construct * * @param string $locale A string representation of the locale */ - private function __construct($locale) { - $this->locale = $locale; + private function __construct(private string $locale) { } /** @@ -40,9 +36,9 @@ public function __toString() { * * @throws InvalidLocaleException */ - public static function parse($locale) { + public static function parse(string $locale): Locale { if (!preg_match('~^[a-z0-9_]{2,20}$~', $locale)) { - throw new InvalidLocaleException("Unrecognized locale: $locale"); + throw new InvalidLocaleException("Unrecognized locale: {$locale}"); } return new Locale($locale); diff --git a/engine/classes/Elgg/PersistentLoginService.php b/engine/classes/Elgg/PersistentLoginService.php index cb248fb7a0a..834cfb270d5 100644 --- a/engine/classes/Elgg/PersistentLoginService.php +++ b/engine/classes/Elgg/PersistentLoginService.php @@ -18,30 +18,9 @@ class PersistentLoginService { use TimeUsing; - /** - * @var array - */ - protected $cookie_config; - - /** - * @var string - */ - protected $cookie_token; - - /** - * @var \ElggSession - */ - protected $session; + protected array $cookie_config; - /** - * @var \Elgg\Security\Crypto - */ - protected $crypto; - - /** - * @var UsersRememberMeCookiesTable - */ - protected $persistent_cookie_table; + protected string $cookie_token; /** * @var callable @@ -59,15 +38,12 @@ class PersistentLoginService { * @param \Elgg\Http\Request $request The request */ public function __construct( - UsersRememberMeCookiesTable $cookie_table, - \ElggSession $session, - \Elgg\Security\Crypto $crypto, - \Elgg\Config $config, - \Elgg\Http\Request $request) { - $this->persistent_cookie_table = $cookie_table; - $this->session = $session; - $this->crypto = $crypto; - + protected UsersRememberMeCookiesTable $cookie_table, + protected \ElggSession $session, + protected \Elgg\Security\Crypto $crypto, + \Elgg\Config $config, + \Elgg\Http\Request $request + ) { $global_cookies_config = $config->getCookieConfig(); $this->cookie_config = $global_cookies_config['remember_me']; @@ -85,7 +61,7 @@ public function makeLoginPersistent(\ElggUser $user): void { $token = $this->generateToken(); $hash = $this->hashToken($token); - $this->persistent_cookie_table->insertHash($user, $hash); + $this->cookie_table->insertHash($user, $hash); $this->setCookie($token); $this->setSessionToken($token); } @@ -98,7 +74,7 @@ public function makeLoginPersistent(\ElggUser $user): void { public function removePersistentLogin(): void { if ($this->cookie_token) { $client_hash = $this->hashToken($this->cookie_token); - $this->persistent_cookie_table->deleteHash($client_hash); + $this->cookie_table->deleteHash($client_hash); } $this->setCookie(''); @@ -114,7 +90,7 @@ public function removePersistentLogin(): void { * @return void */ public function handlePasswordChange(\ElggUser $subject, \ElggUser $modifier = null): void { - $this->persistent_cookie_table->deleteAllHashes($subject); + $this->cookie_table->deleteAllHashes($subject); if (!$modifier || ($modifier->guid !== $subject->guid) || !$this->cookie_token) { return; } @@ -162,7 +138,7 @@ public function getUserFromToken(string $token): ?\ElggUser { return null; } - $user_row = $this->persistent_cookie_table->getRowFromHash($hash); + $user_row = $this->cookie_table->getRowFromHash($hash); if (empty($user_row)) { return null; } @@ -185,7 +161,7 @@ public function updateTokenUsage(\ElggUser $user): ?bool { // update the database record // not interested in number of updated rows, as an update in the same second won't update the row - $this->persistent_cookie_table->updateHash($user, $this->hashToken($this->cookie_token)); + $this->cookie_table->updateHash($user, $this->hashToken($this->cookie_token)); // also update the cookie lifetime client-side $this->setCookie($this->cookie_token); @@ -211,7 +187,7 @@ public function removeExpiredTokens($time): bool { return false; } - return (bool) $this->persistent_cookie_table->deleteExpiredHashes($time->getTimestamp()); + return (bool) $this->cookie_table->deleteExpiredHashes($time->getTimestamp()); } /** diff --git a/engine/classes/Elgg/Plugin/Composer.php b/engine/classes/Elgg/Plugin/Composer.php index 7a37daeb78c..04cf1b5abe6 100644 --- a/engine/classes/Elgg/Plugin/Composer.php +++ b/engine/classes/Elgg/Plugin/Composer.php @@ -16,11 +16,6 @@ */ class Composer { - /** - * @var \ElggPlugin - */ - protected $plugin; - /** * @var \Eloquent\Composer\Configuration\Element\Configuration */ @@ -33,9 +28,7 @@ class Composer { * * @throws ComposerException */ - public function __construct(\ElggPlugin $plugin) { - $this->plugin = $plugin; - + public function __construct(protected \ElggPlugin $plugin) { try { // need to suppress warning because of deprecated notices that get converted to warnings during phpunit $reader = @new \Eloquent\Composer\Configuration\ConfigurationReader; diff --git a/engine/classes/Elgg/Router.php b/engine/classes/Elgg/Router.php index be79b48b9ab..ff2eee22c94 100644 --- a/engine/classes/Elgg/Router.php +++ b/engine/classes/Elgg/Router.php @@ -27,36 +27,6 @@ class Router { use Profilable; - /** - * @var EventsService - */ - protected $events; - - /** - * @var RouteCollection - */ - protected $routes; - - /** - * @var UrlMatcher - */ - protected $matcher; - - /** - * @var HandlersService - */ - protected $handlers; - - /** - * @var ResponseFactory - */ - protected $response; - - /** - * @var Plugins - */ - protected $plugins; - /** * Constructor * @@ -68,19 +38,13 @@ class Router { * @param Plugins $plugins Plugins */ public function __construct( - EventsService $events, - RouteCollection $routes, - UrlMatcher $matcher, - HandlersService $handlers, - ResponseFactory $response, - Plugins $plugins + protected EventsService $events, + protected RouteCollection $routes, + protected UrlMatcher $matcher, + protected HandlersService $handlers, + protected ResponseFactory $response, + protected Plugins $plugins ) { - $this->events = $events; - $this->routes = $routes; - $this->matcher = $matcher; - $this->handlers = $handlers; - $this->response = $response; - $this->plugins = $plugins; } /** @@ -93,7 +57,7 @@ public function __construct( * * @return boolean Whether the request was routed successfully. */ - public function route(HttpRequest $request) { + public function route(HttpRequest $request): bool { $this->beginTimer(['build page']); $request->validate(); diff --git a/engine/classes/Elgg/Security/Hmac.php b/engine/classes/Elgg/Security/Hmac.php index 8a6886bd979..3f661e0d467 100644 --- a/engine/classes/Elgg/Security/Hmac.php +++ b/engine/classes/Elgg/Security/Hmac.php @@ -9,25 +9,12 @@ */ class Hmac { - /** - * @var string - */ - private $key; - /** * @var callable */ - private $comparator; + protected $comparator; - /** - * @var string - */ - private $data; - - /** - * @var string - */ - private $algo; + protected string $data; /** * Constructor @@ -39,8 +26,7 @@ class Hmac { * * @throws \Elgg\Exceptions\InvalidArgumentException */ - public function __construct($key, callable $comparator, $data, $algo = 'sha256') { - $this->key = $key; + public function __construct(protected string $key, callable $comparator, $data, protected string $algo = 'sha256') { $this->comparator = $comparator; if (!$data) { throw new InvalidArgumentException('$data cannot be empty'); @@ -51,7 +37,6 @@ public function __construct($key, callable $comparator, $data, $algo = 'sha256') } $this->data = $data; - $this->algo = $algo; } /** @@ -59,7 +44,7 @@ public function __construct($key, callable $comparator, $data, $algo = 'sha256') * * @return string */ - public function getToken() { + public function getToken(): string { $bytes = hash_hmac($this->algo, $this->data, $this->key, true); return Base64Url::encode($bytes); } @@ -68,9 +53,10 @@ public function getToken() { * Does the MAC match the given token? * * @param string $token HMAC token in Base64URL encoding + * * @return bool */ - public function matchesToken($token) { + public function matchesToken($token): bool { $expected_token = $this->getToken(); return call_user_func($this->comparator, $expected_token, $token); } diff --git a/engine/classes/Elgg/SessionManagerService.php b/engine/classes/Elgg/SessionManagerService.php index b37ee014c20..f9fe957b232 100644 --- a/engine/classes/Elgg/SessionManagerService.php +++ b/engine/classes/Elgg/SessionManagerService.php @@ -14,51 +14,12 @@ * @since 5.0 */ class SessionManagerService { - - /** - * @var EntityCache - */ - protected $entity_cache; - - /** - * @var EventsService - */ - protected $events; - - /** - * @var bool - */ - protected $ignore_access = false; - - /** - * @var \ElggUser|null - */ - protected $logged_in_user; - /** - * @var PersistentLoginService - */ - protected $persistent_login; - - /** - * @var bool - */ - protected $show_disabled_entities = false; - - /** - * @var \ElggSession - */ - protected $session; + protected bool $ignore_access = false; - /** - * @var SessionCache - */ - protected $session_cache; + protected ?\ElggUser $logged_in_user = null; - /** - * @var Translator - */ - protected $translator; + protected bool $show_disabled_entities = false; /** * Constructor @@ -71,19 +32,13 @@ class SessionManagerService { * @param EntityCache $entity_cache the entity cache */ public function __construct( - \ElggSession $session, - EventsService $events, - Translator $translator, - PersistentLoginService $persistent_login, - SessionCache $session_cache, - EntityCache $entity_cache - ) { - $this->session = $session; - $this->events = $events; - $this->translator = $translator; - $this->persistent_login = $persistent_login; - $this->session_cache = $session_cache; - $this->entity_cache = $entity_cache; + protected \ElggSession $session, + protected EventsService $events, + protected Translator $translator, + protected PersistentLoginService $persistent_login, + protected SessionCache $session_cache, + protected EntityCache $entity_cache + ) { } /** diff --git a/engine/classes/Elgg/Structs/Collection/InMemory.php b/engine/classes/Elgg/Structs/Collection/InMemory.php index d40363235bc..44bdc105e62 100644 --- a/engine/classes/Elgg/Structs/Collection/InMemory.php +++ b/engine/classes/Elgg/Structs/Collection/InMemory.php @@ -12,16 +12,12 @@ */ final class InMemory implements Collection { - /** @var array */ - private $items; - /** * Constructor * * @param array $items The set of items in the collection */ - private function __construct(array $items = []) { - $this->items = $items; + private function __construct(protected array $items = []) { } /** diff --git a/engine/classes/Elgg/Upgrade/Batch.php b/engine/classes/Elgg/Upgrade/Batch.php index 0e373433e9a..f4333580766 100644 --- a/engine/classes/Elgg/Upgrade/Batch.php +++ b/engine/classes/Elgg/Upgrade/Batch.php @@ -14,18 +14,12 @@ abstract class Batch { */ const UNKNOWN_COUNT = -1; - /** - * @var \ElggUpgrade - */ - protected $upgrade; - /** * Constructs a upgrade batch * * @param \ElggUpgrade $upgrade the upgrade related to this batch */ - public function __construct(\ElggUpgrade $upgrade = null) { - $this->upgrade = $upgrade; + public function __construct(protected ?\ElggUpgrade $upgrade = null) { } /** diff --git a/engine/classes/Elgg/Upgrade/Loop.php b/engine/classes/Elgg/Upgrade/Loop.php index 87352d356f5..1ae489fe672 100644 --- a/engine/classes/Elgg/Upgrade/Loop.php +++ b/engine/classes/Elgg/Upgrade/Loop.php @@ -16,45 +16,18 @@ class Loop { use Loggable; - /** - * @var \ElggUpgrade - */ - protected $upgrade; - - /** - * @var Result - */ - protected $result; - /** * @var Batch|false */ protected $batch; - /** - * @var int - */ - protected $max_duration; - - /** - * @var int - */ - protected $count; + protected int $max_duration; - /** - * @var int - */ - protected $processed; + protected int $count; - /** - * @var int - */ - protected $offset; + protected int $processed; - /** - * @var Progress - */ - protected $progress; + protected int $offset; /** * Constructor @@ -67,13 +40,13 @@ class Loop { * @throws RuntimeException */ public function __construct( - \ElggUpgrade $upgrade, - Result $result, - Progress $progress, + protected \ElggUpgrade $upgrade, + protected Result $result, + protected Progress $progress, Logger $logger ) { - $this->upgrade = $upgrade; - + $this->setLogger($logger); + // Get the class taking care of the actual upgrading $this->batch = $upgrade->getBatch(); if (!$this->batch) { @@ -83,10 +56,6 @@ public function __construct( ])); } - $this->result = $result; - $this->progress = $progress; - $this->logger = $logger; - $this->count = $this->batch->countItems(); $this->processed = (int) $upgrade->processed; $this->offset = (int) $upgrade->offset; diff --git a/engine/classes/Elgg/UpgradeService.php b/engine/classes/Elgg/UpgradeService.php index 7ef90e9c1da..73283133ad4 100644 --- a/engine/classes/Elgg/UpgradeService.php +++ b/engine/classes/Elgg/UpgradeService.php @@ -23,41 +23,6 @@ class UpgradeService { use Loggable; - /** - * @var Locator - */ - protected $locator; - - /** - * @var Translator - */ - private $translator; - - /** - * @var EventsService - */ - private $events; - - /** - * @var Config - */ - private $config; - - /** - * @var Mutex - */ - private $mutex; - - /** - * @var SystemMessagesService - */ - private $system_messages; - - /** - * @var Progress - */ - protected $progress; - /** * Constructor * @@ -70,28 +35,22 @@ class UpgradeService { * @param Progress $progress Progress */ public function __construct( - Locator $locator, - Translator $translator, - EventsService $events, - Config $config, - Mutex $mutex, - SystemMessagesService $system_messages, - Progress $progress + protected Locator $locator, + protected Translator $translator, + protected EventsService $events, + protected Config $config, + protected Mutex $mutex, + protected SystemMessagesService $system_messages, + protected Progress $progress ) { - $this->locator = $locator; - $this->translator = $translator; - $this->events = $events; - $this->config = $config; - $this->mutex = $mutex; - $this->system_messages = $system_messages; - $this->progress = $progress; } /** * Start an upgrade process + * * @return Promise */ - protected function up() { + protected function up(): Promise { return new Promise(function ($resolve, $reject) { Application::migrate(); @@ -114,9 +73,10 @@ protected function up() { /** * Finish an upgrade process + * * @return Promise */ - protected function down() { + protected function down(): Promise { return new Promise(function ($resolve, $reject) { if (!$this->events->trigger('upgrade', 'system', null)) { return $reject(); @@ -139,7 +99,7 @@ protected function down() { * * @return Promise */ - protected function runUpgrades($upgrades) { + protected function runUpgrades($upgrades): Promise { $promises = []; foreach ($upgrades as $upgrade) { @@ -176,7 +136,7 @@ protected function runUpgrades($upgrades) { * * @return Promise */ - public function run($upgrades = null) { + public function run($upgrades = null): Promise { // turn off time limit set_time_limit(3600); @@ -225,7 +185,7 @@ function ($result) use ($resolve) { * * @return \ElggUpgrade[] */ - public function getPendingUpgrades($async = true) { + public function getPendingUpgrades(bool $async = true): array { $pending = []; $upgrades = $this->locator->locate(); @@ -259,7 +219,7 @@ public function getPendingUpgrades($async = true) { * * @return \ElggUpgrade[] */ - public function getCompletedUpgrades($async = true) { + public function getCompletedUpgrades(bool $async = true): array { // make sure always to return all upgrade entities return elgg_call( ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, @@ -312,7 +272,7 @@ function () use ($async) { * * @return Result */ - public function executeUpgrade(\ElggUpgrade $upgrade, $max_duration = null) { + public function executeUpgrade(\ElggUpgrade $upgrade, int $max_duration = null): Result { // Upgrade also disabled data, so the compatibility is // preserved in case the data ever gets enabled again return elgg_call( diff --git a/engine/classes/Elgg/Users/Accounts.php b/engine/classes/Elgg/Users/Accounts.php index aabd9f8f257..ec2b9f1adb5 100644 --- a/engine/classes/Elgg/Users/Accounts.php +++ b/engine/classes/Elgg/Users/Accounts.php @@ -19,36 +19,6 @@ */ class Accounts { - /** - * @var Config - */ - protected $config; - - /** - * @var Translator - */ - protected $translator; - - /** - * @var PasswordService - */ - protected $passwords; - - /** - * @var EventsService - */ - protected $events; - - /** - * @var EmailService - */ - protected $email; - - /** - * @var PasswordGeneratorService - */ - protected $password_generator; - /** * Constructor * @@ -60,19 +30,13 @@ class Accounts { * @param PasswordGeneratorService $password_generator Password generator service */ public function __construct( - Config $config, - Translator $translator, - PasswordService $passwords, - EventsService $events, - EmailService $email, - PasswordGeneratorService $password_generator + protected Config $config, + protected Translator $translator, + protected PasswordService $passwords, + protected EventsService $events, + protected EmailService $email, + protected PasswordGeneratorService $password_generator ) { - $this->config = $config; - $this->translator = $translator; - $this->passwords = $passwords; - $this->events = $events; - $this->email = $email; - $this->password_generator = $password_generator; } /** diff --git a/engine/classes/Elgg/Validation/ValidationResult.php b/engine/classes/Elgg/Validation/ValidationResult.php index 4b8d34e3080..37e888ab439 100644 --- a/engine/classes/Elgg/Validation/ValidationResult.php +++ b/engine/classes/Elgg/Validation/ValidationResult.php @@ -7,25 +7,9 @@ */ class ValidationResult { - /** - * @var string - */ - protected $name; - - /** - * @var mixed - */ - protected $value; - - /** - * @var string - */ - protected $message; + protected string $message = ''; - /** - * @var string - */ - protected $error; + protected string $error = ''; /** * Constructor @@ -33,9 +17,7 @@ class ValidationResult { * @param string $name Parameter name * @param mixed $value Parameter value */ - public function __construct($name, $value) { - $this->name = $name; - $this->value = $value; + public function __construct(protected string $name, protected $value) { } /** @@ -45,7 +27,7 @@ public function __construct($name, $value) { * * @return void */ - public function pass($message = '') { + public function pass(string $message = ''): void { $this->message = $message; } @@ -56,7 +38,7 @@ public function pass($message = '') { * * @return void */ - public function fail($error = '') { + public function fail(string $error = ''): void { $this->error = $error; } @@ -65,8 +47,8 @@ public function fail($error = '') { * * @return bool */ - public function isValid() { - return !isset($this->error); + public function isValid(): bool { + return $this->error === ''; } /** @@ -74,7 +56,7 @@ public function isValid() { * * @return string */ - public function getName() { + public function getName(): string { return $this->name; } @@ -90,18 +72,18 @@ public function getValue() { /** * Get error message * - * @return mixed + * @return string */ - public function getError() { + public function getError(): string { return $this->error; } /** * Get success message * - * @return mixed + * @return string */ - public function getMessage() { + public function getMessage(): string { return $this->message; } } diff --git a/engine/classes/Elgg/Views/HtmlFormatter.php b/engine/classes/Elgg/Views/HtmlFormatter.php index 6488217dd0c..8854adf0999 100644 --- a/engine/classes/Elgg/Views/HtmlFormatter.php +++ b/engine/classes/Elgg/Views/HtmlFormatter.php @@ -37,12 +37,6 @@ class HtmlFormatter { */ public const MENTION_REGEX = '/]*?>.*?<\/a>|<.*?>|(^|\s|\!|\.|\?|>|\G)+(@([^\s<&]+))/iu'; - protected ViewsService $views; - - protected EventsService $events; - - protected AutoParagraph $autop; - /** * Output constructor. * @@ -51,13 +45,10 @@ class HtmlFormatter { * @param AutoParagraph $autop Paragraph wrapper */ public function __construct( - ViewsService $views, - EventsService $events, - AutoParagraph $autop + protected ViewsService $views, + protected EventsService $events, + protected AutoParagraph $autop ) { - $this->views = $views; - $this->events = $events; - $this->autop = $autop; } /** diff --git a/engine/classes/Elgg/Views/TableColumn/ViewColumn.php b/engine/classes/Elgg/Views/TableColumn/ViewColumn.php index 65b84c11e0b..9aa8b053abe 100644 --- a/engine/classes/Elgg/Views/TableColumn/ViewColumn.php +++ b/engine/classes/Elgg/Views/TableColumn/ViewColumn.php @@ -9,20 +9,7 @@ */ class ViewColumn implements TableColumn { - /** - * @var string - */ - private $heading; - - /** - * @var string - */ - private $view; - - /** - * @var array - */ - private $vars; + protected string $heading; /** * Constructor @@ -31,12 +18,9 @@ class ViewColumn implements TableColumn { * @param string $heading Heading * @param array $vars Vars to merge into the view vars */ - public function __construct($view, $heading = null, $vars = []) { - $this->view = $view; - $this->vars = $vars; - + public function __construct(protected string $view, string $heading = null, protected array $vars = []) { if (!is_string($heading)) { - $heading = elgg_echo("ViewColumn:view:$view"); + $heading = elgg_echo("ViewColumn:view:{$view}"); } $this->heading = $heading; diff --git a/engine/lib/mb_wrapper.php b/engine/lib/mb_wrapper.php index b27df24bc4a..923d9304526 100644 --- a/engine/lib/mb_wrapper.php +++ b/engine/lib/mb_wrapper.php @@ -77,42 +77,6 @@ function elgg_strpos() { return call_user_func_array('strpos', $args); } -/** - * Wrapper function for mb_strrchr(). Falls back to strrchr() if - * mb_strrchr() isn't available. Parameters are passed to the - * wrapped function in the same order they are passed to this - * function. - * - * @return false|string - * @since 1.7.0 - */ -function elgg_strrchr() { - $args = func_get_args(); - if (is_callable('mb_strrchr')) { - return call_user_func_array('mb_strrchr', $args); - } - - return call_user_func_array('strrchr', $args); -} - -/** - * Wrapper function for mb_strripos(). Falls back to strripos() if - * mb_strripos() isn't available. Parameters are passed to the - * wrapped function in the same order they are passed to this - * function. - * - * @return false|int - * @since 1.7.0 - */ -function elgg_strripos() { - $args = func_get_args(); - if (is_callable('mb_strripos')) { - return call_user_func_array('mb_strripos', $args); - } - - return call_user_func_array('strripos', $args); -} - /** * Wrapper function for mb_strrpos(). Falls back to strrpos() if * mb_strrpos() isn't available. Parameters are passed to the