Skip to content

Commit

Permalink
Refactor lib/private
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
  • Loading branch information
shdehnavi committed Jul 9, 2023
1 parent 9bf6911 commit 793cd10
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 163 deletions.
15 changes: 8 additions & 7 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function getGenerator(): Generator {
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
* @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
*/
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null): ISimpleFile {
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
try {
Expand All @@ -208,7 +208,7 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
* @since 19.0.0
*/
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
public function generatePreviews(File $file, array $specifications, $mimeType = null): ISimpleFile {
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
}

Expand All @@ -218,7 +218,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
* @param string $mimeType
* @return boolean
*/
public function isMimeSupported($mimeType = '*') {
public function isMimeSupported($mimeType = '*'): bool {
if (!$this->config->getSystemValueBool('enable_previews', true)) {
return false;
}
Expand Down Expand Up @@ -304,9 +304,9 @@ public function isAvailable(\OCP\Files\FileInfo $file): bool {
* - OC\Preview\SVG
* - OC\Preview\TIFF
*
* @return array
* @return array|null
*/
protected function getEnabledDefaultProvider() {
protected function getEnabledDefaultProvider(): ?array {
if ($this->defaultProviders !== null) {
return $this->defaultProviders;
}
Expand Down Expand Up @@ -340,8 +340,9 @@ protected function getEnabledDefaultProvider() {
*
* @param string $class
* @param string $mimeType
* @param array $options
*/
protected function registerCoreProvider($class, $mimeType, $options = []) {
protected function registerCoreProvider(string $class, string $mimeType, array $options = []): void {
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
$this->registerProvider($mimeType, function () use ($class, $options) {
return new $class($options);
Expand All @@ -352,7 +353,7 @@ protected function registerCoreProvider($class, $mimeType, $options = []) {
/**
* Register the default providers (if enabled)
*/
protected function registerCoreProviders() {
protected function registerCoreProviders(): void {
if ($this->registeredCoreProviders) {
return;
}
Expand Down
37 changes: 16 additions & 21 deletions lib/private/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ class RedisFactory {
public const REDIS_EXTRA_PARAMETERS_MINIMAL_VERSION = '5.3.0';

/** @var \Redis|\RedisCluster */
private $instance;

private SystemConfig $config;

private IEventLogger $eventLogger;
private \Redis|\RedisCluster $instance;

/**
* RedisFactory constructor.
*
* @param SystemConfig $config
*/
public function __construct(SystemConfig $config, IEventLogger $eventLogger) {
$this->config = $config;
$this->eventLogger = $eventLogger;
public function __construct(
private SystemConfig $config,
private IEventLogger $eventLogger,
) {
}

private function create() {
/**
* @throws \Exception
*/
private function create(): void {
$isCluster = in_array('redis.cluster', $this->config->getKeys(), true);
$config = $isCluster
? $this->config->getValue('redis.cluster', [])
Expand All @@ -59,17 +59,9 @@ private function create() {
throw new \Exception('Redis Cluster support is not available');
}

if (isset($config['timeout'])) {
$timeout = $config['timeout'];
} else {
$timeout = 0.0;
}
$timeout = $config['timeout'] ?? 0.0;

if (isset($config['read_timeout'])) {
$readTimeout = $config['read_timeout'];
} else {
$readTimeout = 0.0;
}
$readTimeout = $config['read_timeout'] ?? 0.0;

$auth = null;
if (isset($config['password']) && (string)$config['password'] !== '') {
Expand Down Expand Up @@ -157,7 +149,7 @@ private function create() {
* @return array|null
* @throws \UnexpectedValueException
*/
private function getSslContext($config) {
private function getSslContext(array $config): ?array {
if (isset($config['ssl_context'])) {
if (!$this->isConnectionParametersSupported()) {
throw new \UnexpectedValueException(\sprintf(
Expand All @@ -170,7 +162,10 @@ private function getSslContext($config) {
return null;
}

public function getInstance() {
/**
* @throws \Exception
*/
public function getInstance(): \RedisCluster|\Redis {
if (!$this->isAvailable()) {
throw new \Exception('Redis support is not available');
}
Expand Down
39 changes: 15 additions & 24 deletions lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,24 @@
use Throwable;

class Repair implements IOutput {
/** @var IRepairStep[] */
private array $repairSteps;

private IEventDispatcher $dispatcher;

private string $currentStep;

private LoggerInterface $logger;

/**
* Creates a new repair step runner
*
* @param IRepairStep[] $repairSteps array of RepairStep instances
*/
public function __construct(array $repairSteps, IEventDispatcher $dispatcher, LoggerInterface $logger) {
$this->repairSteps = $repairSteps;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
public function __construct(
private array $repairSteps,
private IEventDispatcher $dispatcher,
private LoggerInterface $logger,
) {
}

/**
* Run a series of repair steps for common problems
*/
public function run() {
public function run(): void {
if (count($this->repairSteps) === 0) {
$this->dispatcher->dispatchTyped(new RepairInfoEvent('No repair steps available'));

Expand All @@ -134,10 +128,10 @@ public function run() {
/**
* Add repair step
*
* @param IRepairStep|string $repairStep repair step
* @param string|IRepairStep $repairStep repair step
* @throws \Exception
*/
public function addStep($repairStep) {
public function addStep(string|IRepairStep $repairStep): void {
if (is_string($repairStep)) {
try {
$s = \OC::$server->get($repairStep);
Expand Down Expand Up @@ -219,7 +213,7 @@ public static function getRepairSteps(): array {
*
* @return IRepairStep[]
*/
public static function getExpensiveRepairSteps() {
public static function getExpensiveRepairSteps(): array {
return [
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
\OC::$server->get(ValidatePhoneNumber::class),
Expand All @@ -232,7 +226,7 @@ public static function getExpensiveRepairSteps() {
*
* @return IRepairStep[]
*/
public static function getBeforeUpgradeRepairSteps() {
public static function getBeforeUpgradeRepairSteps(): array {
/** @var Connection $connection */
$connection = \OC::$server->get(Connection::class);
/** @var ConnectionAdapter $connectionAdapter */
Expand All @@ -251,23 +245,23 @@ public static function getBeforeUpgradeRepairSteps() {
/**
* @param string $message
*/
public function info($message) {
public function info($message): void {
// for now just emit as we did in the past
$this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
}

/**
* @param string $message
*/
public function warning($message) {
public function warning($message): void {
// for now just emit as we did in the past
$this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
}

/**
* @param int $max
*/
public function startProgress($max = 0) {
public function startProgress($max = 0): void {
// for now just emit as we did in the past
$this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
}
Expand All @@ -276,15 +270,12 @@ public function startProgress($max = 0) {
* @param int $step number of step to advance
* @param string $description
*/
public function advance($step = 1, $description = '') {
public function advance($step = 1, $description = ''): void {
// for now just emit as we did in the past
$this->dispatcher->dispatchTyped(new RepairAdvanceEvent($step, $description));
}

/**
* @param int $max
*/
public function finishProgress() {
public function finishProgress(): void {
// for now just emit as we did in the past
$this->dispatcher->dispatchTyped(new RepairFinishEvent());
}
Expand Down
14 changes: 7 additions & 7 deletions lib/private/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
*/
class Search implements ISearch {
/** @var Provider[] */
private $providers = [];
private $registeredProviders = [];
private array $providers = [];
private array $registeredProviders = [];

/**
* Search all providers for $query
Expand All @@ -47,7 +47,7 @@ class Search implements ISearch {
* @param int $size, 0 = all
* @return array An array of OC\Search\Result's
*/
public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) {
public function searchPaged($query, array $inApps = [], $page = 1, $size = 30): array {
$this->initProviders();
$results = [];
foreach ($this->providers as $provider) {
Expand All @@ -74,7 +74,7 @@ public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) {
/**
* Remove all registered search providers
*/
public function clearProviders() {
public function clearProviders(): void {
$this->providers = [];
$this->registeredProviders = [];
}
Expand All @@ -83,7 +83,7 @@ public function clearProviders() {
* Remove one existing search provider
* @param string $provider class name of a OC\Search\Provider
*/
public function removeProvider($provider) {
public function removeProvider($provider): void {
$this->registeredProviders = array_filter(
$this->registeredProviders,
function ($element) use ($provider) {
Expand All @@ -99,14 +99,14 @@ function ($element) use ($provider) {
* @param string $class class name of a OC\Search\Provider
* @param array $options optional
*/
public function registerProvider($class, array $options = []) {
public function registerProvider($class, array $options = []): void {
$this->registeredProviders[] = ['class' => $class, 'options' => $options];
}

/**
* Create instances of all the registered search providers
*/
private function initProviders() {
private function initProviders(): void {
if (! empty($this->providers)) {
return;
}
Expand Down
Loading

0 comments on commit 793cd10

Please sign in to comment.