Skip to content

Commit

Permalink
Merge pull request #14583 from jdalsem/remove_annotations_enabled
Browse files Browse the repository at this point in the history
chore(core): changed constructors to use property promotion
  • Loading branch information
jeabakker committed Mar 21, 2024
2 parents e5407d4 + 53da7ea commit d56ed6d
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 624 deletions.
2 changes: 2 additions & 0 deletions docs/appendix/upgrade-notes/5.x-to-6.0.rst
Expand Up @@ -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
Expand Down
39 changes: 10 additions & 29 deletions engine/classes/Elgg/Cli.php
Expand Up @@ -22,21 +22,6 @@ class Cli {
*/
protected $console;

/**
* @var EventsService
*/
protected $events;

/**
* @var InputInterface
*/
protected $input;

/**
* @var OutputInterface
*/
protected $output;

/**
* Constructor
*
Expand All @@ -45,26 +30,22 @@ 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;
}

/**
* Add CLI tools to the console application
*
* @return void
*/
protected function bootstrap() {
protected function bootstrap(): void {
$commands = array_merge($this->getCoreCommands(), $this->getPluginCommands());
$commands = $this->events->triggerResults('commands', 'cli', [], $commands);

Expand All @@ -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);
}
Expand All @@ -88,7 +69,7 @@ protected function getCoreCommands() {
*
* @return array
*/
protected function getPluginCommands() {
protected function getPluginCommands(): array {
$return = [];

$plugins = elgg_get_plugins('active');
Expand All @@ -112,7 +93,7 @@ protected function getPluginCommands() {
*
* @return void
*/
public function add($command) {
public function add(string $command): void {
if (!class_exists($command)) {
return;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -163,7 +144,7 @@ public function run(bool $bootstrap = true) {
*
* @return InputInterface
*/
public function getInput() {
public function getInput(): InputInterface {
return $this->input;
}

Expand All @@ -172,7 +153,7 @@ public function getInput() {
*
* @return OutputInterface
*/
public function getOutput() {
public function getOutput(): OutputInterface {
return $this->output;
}
}
63 changes: 10 additions & 53 deletions engine/classes/Elgg/EmailService.php
Expand Up @@ -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
*
Expand All @@ -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
) {
}

/**
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
38 changes: 7 additions & 31 deletions engine/classes/Elgg/Event.php
Expand Up @@ -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
*
Expand All @@ -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 = []
) {
}

/**
Expand Down
22 changes: 7 additions & 15 deletions engine/classes/Elgg/Filesystem/File.php
Expand Up @@ -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);

Check warning on line 33 in engine/classes/Elgg/Filesystem/File.php

View check run for this annotation

Scrutinizer / Inspection

engine/classes/Elgg/Filesystem/File.php#L33

The expression ``return pathinfo($this->path, Elgg\Filesystem\PATHINFO_BASENAME)`` could return the type ``array`` which is incompatible with the type-hinted return ``string``. Consider adding an additional type-check to rule them out.
}

Expand All @@ -46,7 +38,7 @@ public function getBasename() {
*
* @return string
*/
public function getContents() {
public function getContents(): string {
return $this->directory->getContents($this->path);
}

Expand All @@ -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);

Check warning on line 59 in engine/classes/Elgg/Filesystem/File.php

View check run for this annotation

Scrutinizer / Inspection

engine/classes/Elgg/Filesystem/File.php#L59

The expression ``return pathinfo($this->path, Elgg\Filesystem\PATHINFO_EXTENSION)`` could return the type ``array`` which is incompatible with the type-hinted return ``string``. Consider adding an additional type-check to rule them out.
}

/**
* @return string The full path to this file.
*/
public function getPath() {
public function getPath(): string {
return $this->directory->getPath($this->path);
}

Expand Down
10 changes: 2 additions & 8 deletions engine/classes/Elgg/Forms/StickyForms.php
Expand Up @@ -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) {
}

/**
Expand Down

0 comments on commit d56ed6d

Please sign in to comment.