Skip to content

Commit

Permalink
chore: cs:fix
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jun 3, 2024
1 parent 3bf4b3c commit b0b190c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/Model/ClassificationLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function fromArray(array $labelRaw): ClassificationLabel {
if (!isset($labelRaw['index'], $labelRaw['tag'], $labelRaw['keywords'], $labelRaw['categories'], $labelRaw['searchExpressions'], $labelRaw['regularExpressions'], $labelRaw['metadataItems'])) {
throw new \ValueError();
}
$metadata = array_values(array_filter(array_map(fn($item) => MetadataItem::fromArray($item), $labelRaw['metadataItems']), fn($item) => $item->getKey() !== ''));
$metadata = array_values(array_filter(array_map(fn ($item) => MetadataItem::fromArray($item), $labelRaw['metadataItems']), fn ($item) => $item->getKey() !== ''));
return new ClassificationLabel($labelRaw['index'], $labelRaw['tag'], $labelRaw['keywords'], $labelRaw['categories'], $labelRaw['searchExpressions'], $labelRaw['regularExpressions'], $metadata);
}

Expand All @@ -127,7 +127,7 @@ public function toArray() : array {
'categories' => $this->getBailsCategories(),
'searchExpressions' => $this->getSearchExpressions(),
'regularExpressions' => $this->getRegularExpressions(),
'metadataItems' => array_map(fn($item) => $item->toArray(), $this->getMetadataItems()),
'metadataItems' => array_map(fn ($item) => $item->toArray(), $this->getMetadataItems()),
];
}

Expand Down
15 changes: 5 additions & 10 deletions lib/Model/MetadataItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@ class MetadataItem {
*/
public function __construct(
private string $key,
private string $value)
{
private string $value) {
}


public function getKey(): string
{
public function getKey(): string {
return $this->key;
}

public function setKey(string $key): MetadataItem
{
public function setKey(string $key): MetadataItem {
$this->key = $key;
return $this;
}

public function getValue(): string
{
public function getValue(): string {
return $this->value;
}

public function setValue(string $value): MetadataItem
{
public function setValue(string $value): MetadataItem {
$this->value = $value;
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
use Sabre\Xml\Reader;
use Sabre\Xml\Service;

class MicrosoftOfficeMetadataProvider implements IMetadataProvider
{
class MicrosoftOfficeMetadataProvider implements IMetadataProvider {

public const ELEMENT_PROPERTIES = '{http://schemas.openxmlformats.org/officeDocument/2006/custom-properties}Properties';
public const ELEMENT_PROPERTY = '{http://schemas.openxmlformats.org/officeDocument/2006/custom-properties}property';
Expand Down Expand Up @@ -68,7 +67,7 @@ public function getMetadataForFile(File $file): array {
if (
$child['name'] === self::ELEMENT_PROPERTY &&
isset($child['attributes'][self::ATTRIBUTE_NAME], $child['value'][0], $child['value'][0]['value'])) {
$items[] = new MetadataItem( $child['attributes'][self::ATTRIBUTE_NAME], $child['value'][0]['value']);
$items[] = new MetadataItem($child['attributes'][self::ATTRIBUTE_NAME], $child['value'][0]['value']);
}
}
return $items;
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/BailsPolicyProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace OCA\Files_Confidential\Service;

use OCA\Files_Confidential\Contract\IBailsPolicy;
use OCA\Files_Confidential\Providers\BailsProviders\MicrosoftOfficeBailsProvider;
use OCA\Files_Confidential\Providers\BailsProviders\OpenDocumentBailsProvider;
use OCA\Files_Confidential\Contract\IBailsPolicy;
use OCP\Files\File;

class BailsPolicyProviderService {
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ClassificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getClassificationLabelForFile(File $file) : ?IClassificationLabe
$content = $this->contentService->getContentForFile($file);
$labelFromContent = ClassificationLabel::findLabelsInText($content, $labels);

$labels = array_values(array_filter([$labelFromMetadata, $labelFromPolicy, $labelFromContent], fn($label) => $label !== null));
$labels = array_values(array_filter([$labelFromMetadata, $labelFromPolicy, $labelFromContent], fn ($label) => $label !== null));

if (count($labels) === 0) {
return null;
Expand Down
1 change: 0 additions & 1 deletion lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use OCA\Files_Confidential\Model\ClassificationLabel;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use Safe\Exceptions\JsonException;

class SettingsService {
public function __construct(
Expand Down
7 changes: 3 additions & 4 deletions test/MetadataProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use OCA\Files_Confidential\Providers\BailsProviders\MicrosoftOfficeBailsProvider;
use OCA\Files_Confidential\Providers\BailsProviders\OpenDocumentBailsProvider;
use OCA\Files_Confidential\Providers\MetadataProviders\MicrosoftOfficeMetadataProvider;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use Test\TestCase;
Expand Down Expand Up @@ -32,10 +31,10 @@ public function setUp(): void {
public function testMicrosoftOfficeProvider() : void {
$this->testFile = $this->userFolder->newFile('/test.pptx', file_get_contents(__DIR__ . '/res/test_mips_metadata.pptx'));
/** @var \OCA\Files_Confidential\Contract\IMetadataProvider $provider */
$provider = \OC::$server->get(\OCA\Files_Confidential\Providers\MetadataProviders\MicrosoftOfficeMetadataProvider::class);
$provider = \OC::$server->get(MicrosoftOfficeMetadataProvider::class);
$metadataItems = $provider->getMetadataForFile($this->testFile);

$array = array_map(fn($item) => $item->toArray(), $metadataItems);
$array = array_map(fn ($item) => $item->toArray(), $metadataItems);
self::assertEquals([
['key' => "MSIP_Label_9a7859fa-fb81-458d-9040-c3b7cffe6362_Enabled", 'value' => 'true'],
['key' => "MSIP_Label_9a7859fa-fb81-458d-9040-c3b7cffe6362_SetDate", 'value' => '2024-01-18T23:42:17Z'],
Expand Down

0 comments on commit b0b190c

Please sign in to comment.