Skip to content

Commit c35f042

Browse files
committed
Refactors Metadata, Migration, and Net.
In lib/private namespace to improve code readability. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
1 parent 912b18b commit c35f042

File tree

9 files changed

+39
-66
lines changed

9 files changed

+39
-66
lines changed

lib/private/Metadata/Capabilities.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
use OCP\IConfig;
2727

2828
class Capabilities implements IPublicCapability {
29-
private IMetadataManager $manager;
30-
private IConfig $config;
31-
32-
public function __construct(IMetadataManager $manager, IConfig $config) {
33-
$this->manager = $manager;
34-
$this->config = $config;
29+
public function __construct(
30+
private IMetadataManager $manager,
31+
private IConfig $config,
32+
) {
3533
}
3634

37-
public function getCapabilities() {
35+
public function getCapabilities(): array {
3836
if ($this->config->getSystemValueBool('enable_file_metadata', true)) {
3937
return ['metadataAvailable' => $this->manager->getCapabilities()];
4038
}

lib/private/Metadata/FileEventListener.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939
* @template-implements IEventListener<NodeWrittenEvent>
4040
*/
4141
class FileEventListener implements IEventListener {
42-
private IMetadataManager $manager;
43-
private LoggerInterface $logger;
44-
45-
public function __construct(IMetadataManager $manager, LoggerInterface $logger) {
46-
$this->manager = $manager;
47-
$this->logger = $logger;
42+
public function __construct(
43+
private IMetadataManager $manager,
44+
private LoggerInterface $logger,
45+
) {
4846
}
4947

5048
private function shouldExtractMetadata(Node $node): bool {

lib/private/Metadata/MetadataManager.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424

2525
class MetadataManager implements IMetadataManager {
2626
/** @var array<string, IMetadataProvider> */
27-
private array $providers;
28-
private array $providerClasses;
29-
private FileMetadataMapper $fileMetadataMapper;
27+
private array $providers = [];
28+
private array $providerClasses = [];
3029

3130
public function __construct(
32-
FileMetadataMapper $fileMetadataMapper
31+
private FileMetadataMapper $fileMetadataMapper,
3332
) {
34-
$this->providers = [];
35-
$this->providerClasses = [];
36-
$this->fileMetadataMapper = $fileMetadataMapper;
37-
3833
// TODO move to another place, where?
3934
$this->registerProvider(ExifProvider::class);
4035
}

lib/private/Metadata/Provider/ExifProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@
2828
use Psr\Log\LoggerInterface;
2929

3030
class ExifProvider implements IMetadataProvider {
31-
private LoggerInterface $logger;
32-
3331
public function __construct(
34-
LoggerInterface $logger
32+
private LoggerInterface $logger,
3533
) {
36-
$this->logger = $logger;
3734
}
3835

3936
public static function groupsProvided(): array {

lib/private/Migration/BackgroundRepair.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@
4141
* @package OC\Migration
4242
*/
4343
class BackgroundRepair extends TimedJob {
44-
private IJobList $jobList;
45-
private LoggerInterface $logger;
46-
private IEventDispatcher $dispatcher;
47-
48-
public function __construct(IEventDispatcher $dispatcher, ITimeFactory $time, LoggerInterface $logger, IJobList $jobList) {
44+
public function __construct(
45+
private IEventDispatcher $dispatcher,
46+
ITimeFactory $time,
47+
private LoggerInterface $logger,
48+
private IJobList $jobList,
49+
) {
4950
parent::__construct($time);
50-
$this->dispatcher = $dispatcher;
51-
$this->logger = $logger;
52-
$this->jobList = $jobList;
5351
$this->setInterval(15 * 60);
5452
}
5553

@@ -58,7 +56,7 @@ public function __construct(IEventDispatcher $dispatcher, ITimeFactory $time, Lo
5856
* @throws \Exception
5957
* @throws \OC\NeedsUpdateException
6058
*/
61-
protected function run($argument) {
59+
protected function run($argument): void {
6260
if (!isset($argument['app']) || !isset($argument['step'])) {
6361
// remove the job - we can never execute it
6462
$this->jobList->remove($this, $this->argument);
@@ -101,7 +99,7 @@ protected function run($argument) {
10199
* @param $app
102100
* @throws NeedsUpdateException
103101
*/
104-
protected function loadApp($app) {
102+
protected function loadApp($app): void {
105103
OC_App::loadApp($app);
106104
}
107105
}

lib/private/Migration/ConsoleOutput.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,31 @@
3434
* @package OC\Migration
3535
*/
3636
class ConsoleOutput implements IOutput {
37-
/** @var OutputInterface */
38-
private $output;
37+
private ?ProgressBar $progressBar = null;
3938

40-
/** @var ProgressBar */
41-
private $progressBar;
42-
43-
public function __construct(OutputInterface $output) {
44-
$this->output = $output;
39+
public function __construct(
40+
private OutputInterface $output,
41+
) {
4542
}
4643

4744
/**
4845
* @param string $message
4946
*/
50-
public function info($message) {
47+
public function info($message): void {
5148
$this->output->writeln("<info>$message</info>");
5249
}
5350

5451
/**
5552
* @param string $message
5653
*/
57-
public function warning($message) {
54+
public function warning($message): void {
5855
$this->output->writeln("<comment>$message</comment>");
5956
}
6057

6158
/**
6259
* @param int $max
6360
*/
64-
public function startProgress($max = 0) {
61+
public function startProgress($max = 0): void {
6562
if (!is_null($this->progressBar)) {
6663
$this->progressBar->finish();
6764
}
@@ -73,7 +70,7 @@ public function startProgress($max = 0) {
7370
* @param int $step
7471
* @param string $description
7572
*/
76-
public function advance($step = 1, $description = '') {
73+
public function advance($step = 1, $description = ''): void {
7774
if (is_null($this->progressBar)) {
7875
$this->progressBar = new ProgressBar($this->output);
7976
$this->progressBar->start();
@@ -84,7 +81,7 @@ public function advance($step = 1, $description = '') {
8481
}
8582
}
8683

87-
public function finishProgress() {
84+
public function finishProgress(): void {
8885
if (is_null($this->progressBar)) {
8986
return;
9087
}

lib/private/Migration/SimpleOutput.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,46 @@
3333
* @package OC\Migration
3434
*/
3535
class SimpleOutput implements IOutput {
36-
private LoggerInterface $logger;
37-
private $appName;
38-
39-
public function __construct(LoggerInterface $logger, $appName) {
40-
$this->logger = $logger;
41-
$this->appName = $appName;
36+
public function __construct(
37+
private LoggerInterface $logger,
38+
private $appName,
39+
) {
4240
}
4341

4442
/**
4543
* @param string $message
4644
* @since 9.1.0
4745
*/
48-
public function info($message) {
46+
public function info($message): void {
4947
$this->logger->info($message, ['app' => $this->appName]);
5048
}
5149

5250
/**
5351
* @param string $message
5452
* @since 9.1.0
5553
*/
56-
public function warning($message) {
54+
public function warning($message): void {
5755
$this->logger->warning($message, ['app' => $this->appName]);
5856
}
5957

6058
/**
6159
* @param int $max
6260
* @since 9.1.0
6361
*/
64-
public function startProgress($max = 0) {
62+
public function startProgress($max = 0): void {
6563
}
6664

6765
/**
6866
* @param int $step
6967
* @param string $description
7068
* @since 9.1.0
7169
*/
72-
public function advance($step = 1, $description = '') {
70+
public function advance($step = 1, $description = ''): void {
7371
}
7472

7573
/**
7674
* @since 9.1.0
7775
*/
78-
public function finishProgress() {
76+
public function finishProgress(): void {
7977
}
8078
}

lib/private/Net/HostnameClassifier.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ class HostnameClassifier {
5252
* Check host identifier for local hostname
5353
*
5454
* IP addresses are not considered local. Use the IpAddressClassifier for those.
55-
*
56-
* @param string $hostname
57-
*
58-
* @return bool
5955
*/
6056
public function isLocalHostname(string $hostname): bool {
6157
// Disallow local network top-level domains from RFC 6762

lib/private/Net/IpAddressClassifier.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class IpAddressClassifier {
4646
* Check host identifier for local IPv4 and IPv6 address ranges
4747
*
4848
* Hostnames are not considered local. Use the HostnameClassifier for those.
49-
*
50-
* @param string $ip
51-
*
52-
* @return bool
5349
*/
5450
public function isLocalAddress(string $ip): bool {
5551
$parsedIp = Factory::parseAddressString(

0 commit comments

Comments
 (0)