Refactors Metadata, Migration, and Net.

In lib/private namespace to improve code readability.

Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
pull/39109/head
Faraz Samapoor 11 months ago
parent d4393174fc
commit cbc47a9890

@ -26,15 +26,13 @@ use OCP\Capabilities\IPublicCapability;
use OCP\IConfig; use OCP\IConfig;
class Capabilities implements IPublicCapability { class Capabilities implements IPublicCapability {
private IMetadataManager $manager; public function __construct(
private IConfig $config; private IMetadataManager $manager,
private IConfig $config,
public function __construct(IMetadataManager $manager, IConfig $config) { ) {
$this->manager = $manager;
$this->config = $config;
} }
public function getCapabilities() { public function getCapabilities(): array {
if ($this->config->getSystemValueBool('enable_file_metadata', true)) { if ($this->config->getSystemValueBool('enable_file_metadata', true)) {
return ['metadataAvailable' => $this->manager->getCapabilities()]; return ['metadataAvailable' => $this->manager->getCapabilities()];
} }

@ -39,12 +39,10 @@ use Psr\Log\LoggerInterface;
* @template-implements IEventListener<NodeWrittenEvent> * @template-implements IEventListener<NodeWrittenEvent>
*/ */
class FileEventListener implements IEventListener { class FileEventListener implements IEventListener {
private IMetadataManager $manager; public function __construct(
private LoggerInterface $logger; private IMetadataManager $manager,
private LoggerInterface $logger,
public function __construct(IMetadataManager $manager, LoggerInterface $logger) { ) {
$this->manager = $manager;
$this->logger = $logger;
} }
private function shouldExtractMetadata(Node $node): bool { private function shouldExtractMetadata(Node $node): bool {

@ -24,17 +24,12 @@ use OCP\Files\File;
class MetadataManager implements IMetadataManager { class MetadataManager implements IMetadataManager {
/** @var array<string, IMetadataProvider> */ /** @var array<string, IMetadataProvider> */
private array $providers; private array $providers = [];
private array $providerClasses; private array $providerClasses = [];
private FileMetadataMapper $fileMetadataMapper;
public function __construct( public function __construct(
FileMetadataMapper $fileMetadataMapper private FileMetadataMapper $fileMetadataMapper,
) { ) {
$this->providers = [];
$this->providerClasses = [];
$this->fileMetadataMapper = $fileMetadataMapper;
// TODO move to another place, where? // TODO move to another place, where?
$this->registerProvider(ExifProvider::class); $this->registerProvider(ExifProvider::class);
} }

@ -28,12 +28,9 @@ use OCP\Files\File;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class ExifProvider implements IMetadataProvider { class ExifProvider implements IMetadataProvider {
private LoggerInterface $logger;
public function __construct( public function __construct(
LoggerInterface $logger private LoggerInterface $logger,
) { ) {
$this->logger = $logger;
} }
public static function groupsProvided(): array { public static function groupsProvided(): array {

@ -41,15 +41,13 @@ use Psr\Log\LoggerInterface;
* @package OC\Migration * @package OC\Migration
*/ */
class BackgroundRepair extends TimedJob { class BackgroundRepair extends TimedJob {
private IJobList $jobList; public function __construct(
private LoggerInterface $logger; private IEventDispatcher $dispatcher,
private IEventDispatcher $dispatcher; ITimeFactory $time,
private LoggerInterface $logger,
public function __construct(IEventDispatcher $dispatcher, ITimeFactory $time, LoggerInterface $logger, IJobList $jobList) { private IJobList $jobList,
) {
parent::__construct($time); parent::__construct($time);
$this->dispatcher = $dispatcher;
$this->logger = $logger;
$this->jobList = $jobList;
$this->setInterval(15 * 60); $this->setInterval(15 * 60);
} }
@ -58,7 +56,7 @@ class BackgroundRepair extends TimedJob {
* @throws \Exception * @throws \Exception
* @throws \OC\NeedsUpdateException * @throws \OC\NeedsUpdateException
*/ */
protected function run($argument) { protected function run($argument): void {
if (!isset($argument['app']) || !isset($argument['step'])) { if (!isset($argument['app']) || !isset($argument['step'])) {
// remove the job - we can never execute it // remove the job - we can never execute it
$this->jobList->remove($this, $this->argument); $this->jobList->remove($this, $this->argument);
@ -101,7 +99,7 @@ class BackgroundRepair extends TimedJob {
* @param $app * @param $app
* @throws NeedsUpdateException * @throws NeedsUpdateException
*/ */
protected function loadApp($app) { protected function loadApp($app): void {
OC_App::loadApp($app); OC_App::loadApp($app);
} }
} }

@ -34,34 +34,31 @@ use Symfony\Component\Console\Output\OutputInterface;
* @package OC\Migration * @package OC\Migration
*/ */
class ConsoleOutput implements IOutput { class ConsoleOutput implements IOutput {
/** @var OutputInterface */ private ?ProgressBar $progressBar = null;
private $output;
/** @var ProgressBar */ public function __construct(
private $progressBar; private OutputInterface $output,
) {
public function __construct(OutputInterface $output) {
$this->output = $output;
} }
/** /**
* @param string $message * @param string $message
*/ */
public function info($message) { public function info($message): void {
$this->output->writeln("<info>$message</info>"); $this->output->writeln("<info>$message</info>");
} }
/** /**
* @param string $message * @param string $message
*/ */
public function warning($message) { public function warning($message): void {
$this->output->writeln("<comment>$message</comment>"); $this->output->writeln("<comment>$message</comment>");
} }
/** /**
* @param int $max * @param int $max
*/ */
public function startProgress($max = 0) { public function startProgress($max = 0): void {
if (!is_null($this->progressBar)) { if (!is_null($this->progressBar)) {
$this->progressBar->finish(); $this->progressBar->finish();
} }
@ -73,7 +70,7 @@ class ConsoleOutput implements IOutput {
* @param int $step * @param int $step
* @param string $description * @param string $description
*/ */
public function advance($step = 1, $description = '') { public function advance($step = 1, $description = ''): void {
if (is_null($this->progressBar)) { if (is_null($this->progressBar)) {
$this->progressBar = new ProgressBar($this->output); $this->progressBar = new ProgressBar($this->output);
$this->progressBar->start(); $this->progressBar->start();
@ -84,7 +81,7 @@ class ConsoleOutput implements IOutput {
} }
} }
public function finishProgress() { public function finishProgress(): void {
if (is_null($this->progressBar)) { if (is_null($this->progressBar)) {
return; return;
} }

@ -33,19 +33,17 @@ use Psr\Log\LoggerInterface;
* @package OC\Migration * @package OC\Migration
*/ */
class SimpleOutput implements IOutput { class SimpleOutput implements IOutput {
private LoggerInterface $logger; public function __construct(
private $appName; private LoggerInterface $logger,
private $appName,
public function __construct(LoggerInterface $logger, $appName) { ) {
$this->logger = $logger;
$this->appName = $appName;
} }
/** /**
* @param string $message * @param string $message
* @since 9.1.0 * @since 9.1.0
*/ */
public function info($message) { public function info($message): void {
$this->logger->info($message, ['app' => $this->appName]); $this->logger->info($message, ['app' => $this->appName]);
} }
@ -53,7 +51,7 @@ class SimpleOutput implements IOutput {
* @param string $message * @param string $message
* @since 9.1.0 * @since 9.1.0
*/ */
public function warning($message) { public function warning($message): void {
$this->logger->warning($message, ['app' => $this->appName]); $this->logger->warning($message, ['app' => $this->appName]);
} }
@ -61,7 +59,7 @@ class SimpleOutput implements IOutput {
* @param int $max * @param int $max
* @since 9.1.0 * @since 9.1.0
*/ */
public function startProgress($max = 0) { public function startProgress($max = 0): void {
} }
/** /**
@ -69,12 +67,12 @@ class SimpleOutput implements IOutput {
* @param string $description * @param string $description
* @since 9.1.0 * @since 9.1.0
*/ */
public function advance($step = 1, $description = '') { public function advance($step = 1, $description = ''): void {
} }
/** /**
* @since 9.1.0 * @since 9.1.0
*/ */
public function finishProgress() { public function finishProgress(): void {
} }
} }

@ -52,10 +52,6 @@ class HostnameClassifier {
* Check host identifier for local hostname * Check host identifier for local hostname
* *
* IP addresses are not considered local. Use the IpAddressClassifier for those. * IP addresses are not considered local. Use the IpAddressClassifier for those.
*
* @param string $hostname
*
* @return bool
*/ */
public function isLocalHostname(string $hostname): bool { public function isLocalHostname(string $hostname): bool {
// Disallow local network top-level domains from RFC 6762 // Disallow local network top-level domains from RFC 6762

@ -46,10 +46,6 @@ class IpAddressClassifier {
* Check host identifier for local IPv4 and IPv6 address ranges * Check host identifier for local IPv4 and IPv6 address ranges
* *
* Hostnames are not considered local. Use the HostnameClassifier for those. * Hostnames are not considered local. Use the HostnameClassifier for those.
*
* @param string $ip
*
* @return bool
*/ */
public function isLocalAddress(string $ip): bool { public function isLocalAddress(string $ip): bool {
$parsedIp = Factory::parseAddressString( $parsedIp = Factory::parseAddressString(

Loading…
Cancel
Save