Skip to content

Commit

Permalink
refactor: Autofix code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 6, 2021
1 parent 666aa37 commit a0a2275
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
46 changes: 25 additions & 21 deletions src/Discovery/WopiDiscovery.php
Expand Up @@ -10,7 +10,6 @@
namespace ChampsLibres\WopiLib\Discovery;

use loophp\psr17\Psr17Interface;
use LSS\XML2Array;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Client\ClientInterface;
use SimpleXMLElement;
Expand All @@ -25,22 +24,33 @@ final class WopiDiscovery implements WopiDiscoveryInterface

private Psr17Interface $psr17;

public function __construct(array $configuration, ClientInterface $client, Psr17Interface $psr17, CacheItemPoolInterface $cache)
{
public function __construct(
array $configuration,
ClientInterface $client,
Psr17Interface $psr17,
CacheItemPoolInterface $cache
) {
$this->baseUrl = $configuration['server'];
$this->client = $client;
$this->psr17 = $psr17;
$this->cache = $cache;
}

public function refresh(): void
public function discoverExtension(string $extension): array
{
$this->discoverRaw();
}
$discovery = $this->discover();

private function discover(): SimpleXMLElement
{
return simplexml_load_string($this->discoverRaw());
$extensions = [];

foreach ($discovery->xpath('//net-zone/app') as $app) {
$appName = (string) $app['name'];

foreach ($app->xpath(sprintf("action[@ext='%s']", $extension)) as $action) {
$extensions[] = array_merge(current($action->attributes()), ['name' => $appName]);
}
}

return $extensions;
}

public function getCapabilities(): array
Expand All @@ -54,20 +64,14 @@ public function getCapabilities(): array
return json_decode($this->request($url), true);
}

public function discoverExtension(string $extension): array
public function refresh(): void
{
$discovery = $this->discover();

$extensions = [];
foreach ($discovery->xpath("//net-zone/app") as $app) {
$appName = (string) $app['name'];

foreach ($app->xpath(sprintf("action[@ext='%s']", $extension)) as $action) {
$extensions[] = array_merge(current($action->attributes()), ['name' => $appName]);
}
}
$this->discoverRaw();
}

return $extensions;
private function discover(): SimpleXMLElement
{
return simplexml_load_string($this->discoverRaw());
}

private function discoverRaw(): string
Expand Down
5 changes: 2 additions & 3 deletions src/Discovery/WopiDiscoveryInterface.php
Expand Up @@ -11,10 +11,9 @@

interface WopiDiscoveryInterface
{
public function refresh(): void;
public function discoverExtension(string $extension): array;

public function getCapabilities(): array;

public function discoverExtension(string $extension): array;

public function refresh(): void;
}

0 comments on commit a0a2275

Please sign in to comment.