Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Oct 15, 2024
1 parent 26f3284 commit e847d8d
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 151 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'themes' => ['url' => '/api/themes'],
'attachments' => ['url' => '/api/attachments'],
'catalogi' => ['url' => '/api/catalogi'],
'listing' => ['url' => '/api/listing'],
'listings' => ['url' => '/api/listings'],
],
'routes' => [
// Custom
Expand Down
12 changes: 6 additions & 6 deletions composer-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function checkPlatform(&$warnings, $quiet, $disableTls, $install)
unset($warnings['openssl']);
}

if (!empty($errors)) {
if (empty($errors) === false) {
// Composer-Setup.exe uses "Some settings" to flag platform errors
out('Some settings on your machine make Composer unable to work properly.', 'error');
out('Make sure that you fix the issues listed below and run this script again:', 'error');
Expand Down Expand Up @@ -517,7 +517,7 @@ function outputIssues($issues)
*/
function showWarnings($warnings)
{
if (!empty($warnings)) {
if (empty($warnings) === false) {
out('Some settings on your machine may cause stability issues with Composer.', 'error');
out('If you encounter issues, try to change the following:', 'error');
outputIssues($warnings);
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public function __construct($disableTls = false, $cafile = false)
{
$this->disableTls = $disableTls;
if ($this->disableTls === false) {
if (!empty($cafile) && !is_dir($cafile)) {
if (empty($cafile) === false && is_dir($cafile) === false) {
if (!is_readable($cafile) || !validateCaFile(file_get_contents($cafile))) {
throw new RuntimeException('The configured cafile (' .$cafile. ') was not valid or could not be read.');
}
Expand Down Expand Up @@ -1506,7 +1506,7 @@ protected function getMergedStreamContext($url)
}

// Prefer CGI_HTTP_PROXY if available
if (!empty($_SERVER['CGI_HTTP_PROXY'])) {
if (empty($_SERVER['CGI_HTTP_PROXY']) === false) {
$proxy = parse_url($_SERVER['CGI_HTTP_PROXY']);
}

Expand All @@ -1516,8 +1516,8 @@ protected function getMergedStreamContext($url)
}

// Remove proxy if URL matches no_proxy directive
if (!empty($_SERVER['NO_PROXY']) || !empty($_SERVER['no_proxy']) && parse_url($url, PHP_URL_HOST)) {
$pattern = new NoProxyPattern(!empty($_SERVER['no_proxy']) ? $_SERVER['no_proxy'] : $_SERVER['NO_PROXY']);
if (empty($_SERVER['NO_PROXY']) === false || empty($_SERVER['no_proxy']) === false && parse_url($url, PHP_URL_HOST) === true) {
$pattern = new NoProxyPattern(empty($_SERVER['no_proxy']) === false ? $_SERVER['no_proxy'] : $_SERVER['NO_PROXY']);
if ($pattern->test($url)) {
unset($proxy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
use OCA\OpenCatalogi\Service\ObjectService;
use OCA\OpenCatalogi\Service\DirectoryService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Controller for handling Listing-related operations
*/
class ListingController extends Controller
class ListingsController extends Controller
{
/**
* Constructor for ListingController
* Constructor for ListingsController
*
* @param string $appName The name of the app
* @param IRequest $request The request object
Expand All @@ -38,14 +42,15 @@ public function __construct(
parent::__construct($appName, $request);
}

/**
* Retrieve a list of listings based on provided filters and parameters.
*
* @return JSONResponse JSON response containing the list of listings and total count
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* Retrieve a list of listings based on provided filters and parameters.
*
* @return JSONResponse JSON response containing the list of listings and total count
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(): JSONResponse
{
// Retrieve all request parameters
Expand All @@ -58,15 +63,17 @@ public function index(): JSONResponse
return new JSONResponse($data);
}

/**
* Retrieve a specific listing by its ID.
*
* @param string|int $id The ID of the listing to retrieve
* @return JSONResponse JSON response containing the requested listing
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* Retrieve a specific listing by its ID.
*
* @param string|int $id The ID of the listing to retrieve
*
* @return JSONResponse JSON response containing the requested listing
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function show(string|int $id): JSONResponse
{
// Fetch the listing object by its ID
Expand All @@ -76,14 +83,15 @@ public function show(string|int $id): JSONResponse
return new JSONResponse($object);
}

/**
* Create a new listing.
*
* @return JSONResponse The response containing the created listing object.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* Create a new listing.
*
* @return JSONResponse The response containing the created listing object.
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function create(): JSONResponse
{
// Get all parameters from the request
Expand All @@ -99,15 +107,17 @@ public function create(): JSONResponse
return new JSONResponse($object);
}

/**
* Update an existing listing.
*
* @param string|int $id The ID of the listing to update.
* @return JSONResponse The response containing the updated listing object.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* Update an existing listing.
*
* @param string|int $id The ID of the listing to update.
*
* @return JSONResponse The response containing the updated listing object.
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function update(string|int $id): JSONResponse
{
// Get all parameters from the request
Expand All @@ -127,8 +137,10 @@ public function update(string|int $id): JSONResponse
* Delete a listing.
*
* @param string|int $id The ID of the listing to delete.
*
* @return JSONResponse The response indicating the result of the deletion.
*
* @throws ContainerExceptionInterface|NotFoundExceptionInterface|\OCP\DB\Exception
*
* @NoAdminRequired
* @NoCSRFRequired
*/
Expand All @@ -145,6 +157,7 @@ public function destroy(string|int $id): JSONResponse
* Synchronize a listing or all listings.
*
* @param string|null $id The ID of the listing to synchronize (optional).
*
* @return JSONResponse The response indicating the result of the synchronization.
*
* @NoAdminRequired
Expand All @@ -163,10 +176,10 @@ public function synchronise(?string $id = null): JSONResponse
* Add a new listing from a URL.
*
* @return JSONResponse The response indicating the result of adding the listing.
* @throws GuzzleException
*
* @NoAdminRequired
* @NoCSRFRequired
* @throws GuzzleException
*/
public function add(): JSONResponse
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function index(): JSONResponse

// Check if the OpenRegister service is available
$openRegisters = $this->objectService->getOpenRegisters();
if($openRegisters !== null) {
if ($openRegisters !== null) {
$data['openRegisters'] = true;
$data['availableRegisters'] = $openRegisters->getRegisters();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/AttachmentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function createFromArray(array $object): Attachment
$attachment->hydrate(object: $object);

// Set uuid if not provided
if($attachment->getUuid() === null){
if ($attachment->getUuid() === null){
$attachment->setUuid(Uuid::v4());
}

Expand All @@ -121,8 +121,8 @@ public function createFromArray(array $object): Attachment
public function updateFromArray(int $id, array $object): Attachment
{
$attachment = $this->find($id);
$attachment->hydrate($object);
$attachment->hydrate($object);

// Update the version
$version = explode('.', $attachment->getVersion());
$version[2] = (int)$version[2] + 1;
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/CatalogMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
}

// Apply search conditions
if (!empty($searchConditions)) {
if (empty($searchConditions) === false) {
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
foreach ($searchParams as $param => $value) {
$qb->setParameter($param, $value);
Expand All @@ -122,7 +122,7 @@ public function createFromArray(array $object): Catalog
$catalog->hydrate(object: $object);

// Set uuid if not provided
if($catalog->getUuid() === null){
if ($catalog->getUuid() === null){
$catalog->setUuid(Uuid::v4());
}

Expand All @@ -139,8 +139,8 @@ public function createFromArray(array $object): Catalog
public function updateFromArray(int $id, array $object): Catalog
{
$catalog = $this->find($id);
$catalog->hydrate($object);
$catalog->hydrate($object);

// Update the version
$version = explode('.', $catalog->getVersion());
$version[2] = (int)$version[2] + 1;
Expand Down
9 changes: 6 additions & 3 deletions lib/Db/ListingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCA\OpenCatalogi\Db\Listing;
use OCA\OpenCatalogi\Db\Organization;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand Down Expand Up @@ -170,7 +171,7 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
}

// Apply search conditions
if (!empty($searchConditions)) {
if (empty($searchConditions) === false) {
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
foreach ($searchParams as $param => $value) {
$qb->setParameter($param, $value);
Expand All @@ -186,7 +187,9 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
*
* @param string $catalog The catalog ID to search for, should be a UUID
* @param string $directory The directory to search for, should be a URL
*
* @return Listing|null The found Listing entity or null if not found
* @throws MultipleObjectsReturnedException|Exception
*/
public function findByCatalogIdAndDirectory(string $catalog, string $directory): ?Listing
{
Expand Down Expand Up @@ -217,7 +220,7 @@ public function createFromArray(array $object): Listing
$listing->hydrate(object: $object);

// Set UUID if not provided
if($listing->getUuid() === null){
if ($listing->getUuid() === null){
$listing->setUuid(Uuid::v4());
}

Expand All @@ -235,7 +238,7 @@ public function updateFromArray(int $id, array $object): Listing
{
$listing = $this->find($id);
$listing->hydrate($object);

// Update the version
$version = explode('.', $listing->getVersion());
$version[2] = (int)$version[2] + 1;
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/OrganizationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
}

// Apply search conditions
if (!empty($searchConditions)) {
if (empty($searchConditions) === false) {
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
foreach ($searchParams as $param => $value) {
$qb->setParameter($param, $value);
Expand All @@ -124,7 +124,7 @@ public function createFromArray(array $object): Organization
$organization->hydrate(object: $object);

// Set uuid if not provided
if($organization->getUuid() === null){
if ($organization->getUuid() === null){
$organization->setUuid(Uuid::v4());
}
return $this->insert(entity: $organization);
Expand All @@ -141,7 +141,7 @@ public function updateFromArray(int $id, array $object): Organization
{
$organization = $this->find($id);
$organization->hydrate($object);

// Update the version
$version = explode('.', $organization->getVersion());
$version[2] = (int)$version[2] + 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function hydrate(array $object): self
}
}

if (!isset($object['published'])) {
if (isset($object['published']) === false) {
$object['published'] = null;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Db/PublicationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function count(?array $filters = [], ?array $searchConditions = [], ?arra

$qb = $this->addFilters(queryBuilder: $qb, filters: $filters);

if (!empty($searchConditions)) {
if (empty($searchConditions) === false) {
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
foreach ($searchParams as $param => $value) {
$qb->setParameter($param, $value);
Expand Down Expand Up @@ -182,7 +182,7 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
$qb = $this->addFilters(queryBuilder: $qb, filters: $filters);

// Add search conditions
if (!empty($searchConditions)) {
if (empty($searchConditions) === false) {
foreach ($searchConditions as $condition) {
$qb->andWhere($condition);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public function createFromArray(array $object): Publication
$publication->hydrate(object: $object);

// Set uuid if not provided
if($publication->getUuid() === null){
if ($publication->getUuid() === null){
$publication->setUuid(Uuid::v4());
}

Expand All @@ -250,7 +250,7 @@ public function updateFromArray(int $id, array $object): Publication
{
$publication = $this->find(id: $id);
$publication->hydrate(object: $object);

// Update the version
$version = explode('.', $publication->getVersion());
$version[2] = (int)$version[2] + 1;
Expand Down
Loading

0 comments on commit e847d8d

Please sign in to comment.