Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
cd galette-core/galette/plugins/plugin-maps
../../vendor/bin/phpcs lib/ ./*.php

- name: CS Fixer
if: matrix.php-versions == '8.1'
run: |
cd galette-core/galette/plugins/plugin-maps
../../vendor/bin/php-cs-fixer check --show-progress=dots --verbose --diff

- name: Twig CS
run: |
cd galette-core/galette/plugins/plugin-maps
Expand Down
23 changes: 23 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in([
__DIR__ . '/lib',
__DIR__ . '/tests',
])
;

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.plugin-galette-maps.cache')
->setRules([
'@PSR12' => true,
'@PER-CS' => true,
'@PHP82Migration' => true,
'trailing_comma_in_multiline' => false,
'cast_spaces' => false,
'single_line_empty_body' => false,
'no_unused_imports' => true
])
->setFinder($finder)
;
3 changes: 1 addition & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ build:
override:
- composer self-update
- git clone --depth=1 https://github.com/galette/galette -b develop galette && pushd galette
- ./bin/install_deps && popd

nodes:

analysis:
environment:
php:
version: 8.1
version: 8.2

project_setup:
override:
Expand Down
2 changes: 1 addition & 1 deletion _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'Maps features', //Short description
'Johan Cwiklinski', //Author
'2.1.2', //Version
'1.1.4', //Galette compatible version
'1.2.0', //Galette compatible version
'maps', //routing name and translation domain
'2024-10-20', //Release date
[ //Permissions needed
Expand Down
4 changes: 2 additions & 2 deletions lib/GaletteMaps/Controllers/MapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public function localizeMember(Request $request, Response $response, ?int $id =
if ($id === null) {
$id = (int)$this->login->id;
}
$deps = array(
$deps = [
'picture' => false,
'groups' => false,
'dues' => false
);
];
$member = new Adherent($this->zdb, $id, $deps);

if (
Expand Down
40 changes: 20 additions & 20 deletions lib/GaletteMaps/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getCoords(int $id): array|ArrayObject
if ($results->count() > 0) {
return $results->current();
} else {
return array();
return [];
}
} catch (\Exception $e) {
if ($e->getCode() == '42S02') {
Expand All @@ -73,7 +73,7 @@ public function getCoords(int $id): array|ArrayObject
} else {
Analog::log(
'Unable to retrieve members coordinates for "' .
$id . '". | ' . $e->getMessage(),
$id . '". | ' . $e->getMessage(),
Analog::WARNING
);
}
Expand All @@ -94,9 +94,9 @@ public function listCoords(): array
try {
$select = $zdb->select($this->getTableName(), 'c');
$select->join(
array(
[
'a' => PREFIX_DB . Adherent::TABLE
),
],
'a.' . self::PK . '=' . 'c.' . self::PK
)->where->equalTo(
'activite_adh',
Expand All @@ -110,9 +110,9 @@ public function listCoords(): array
) {
//limit query to public up-to-date profiles
$select->where(
array(
[
new PredicateSet(
array(
[
new Operator(
'date_echeance',
'>=',
Expand All @@ -123,31 +123,31 @@ public function listCoords(): array
'=',
new Expression('true')
)
),
],
PredicateSet::OP_OR
),
new PredicateSet(
array(
[
new Operator(
'bool_display_info',
'=',
new Expression('true')
)
)
]
)
)
]
);

if ($login->isLogged() && !$login->isSuperAdmin()) {
$select->where(
new PredicateSet(
array(
[
new Operator(
'a.' . Adherent::PK,
'=',
$login->id
)
)
]
),
PredicateSet::OP_OR
);
Expand All @@ -156,16 +156,16 @@ public function listCoords(): array

$results = $zdb->execute($select);

$res = array();
$res = [];
foreach ($results as $r) {
$a = new Adherent($zdb, $r);
$m = array(
$m = [
'id_adh' => $a->id,
'lat' => $r->latitude,
'lng' => $r->longitude,
'name' => $a->sname,
'nickname' => $a->nickname
);
];
if ($a->isCompany()) {
$m['company'] = $a->company_name;
}
Expand Down Expand Up @@ -209,21 +209,21 @@ public function setCoords(int $id, float $latitude, float $longitude): bool
//coordinates does not exist yet
$insert = $zdb->insert($this->getTableName());
$insert->values(
array(
[
self::PK => $id,
'latitude' => $latitude,
'longitude' => $longitude
)
]
);
$results = $zdb->execute($insert);
} else {
//coordinates already exists, just update
$update = $zdb->update($this->getTableName());
$update->set(
array(
[
'latitude' => $latitude,
'longitude' => $longitude
)
]
)->where(
[self::PK => $id]
);
Expand Down Expand Up @@ -272,6 +272,6 @@ public function removeCoords(int $id): bool
*/
protected function getTableName(): string
{
return MAPS_PREFIX . self::TABLE;
return MAPS_PREFIX . self::TABLE;
}
}
14 changes: 6 additions & 8 deletions lib/GaletteMaps/NominatimTowns.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
namespace GaletteMaps;

use Analog\Analog;
use Laminas\Db\Sql\Predicate\PredicateSet;
use Laminas\Db\Sql\Predicate\Expression;
use Galette\Core\Preferences;

/**
Expand All @@ -39,10 +37,10 @@ class NominatimTowns
private Preferences $preferences;

/** @var array<string, string> */
private array $query_options = array(
private array $query_options = [
'format' => 'xml',
'addressdetails' => '1'
);
];
private string $uri = 'http://nominatim.openstreetmap.org/search';

/**
Expand Down Expand Up @@ -77,7 +75,7 @@ public function search(string $town, ?string $country = null): array
$options['country'] = $country;
}

$url_options = array();
$url_options = [];
foreach ($options as $key => $value) {
$url_options[] = $key . '=' . urlencode($value);
}
Expand Down Expand Up @@ -110,7 +108,7 @@ public function search(string $town, ?string $country = null): array
$xml = new \SimpleXMLElement($response);
$towns = $xml->xpath('//place');

$results = array();
$results = [];
foreach ($towns as $town) {
if ($town->city || $town->town || $town->village) {
$unique = true;
Expand Down Expand Up @@ -139,11 +137,11 @@ public function search(string $town, ?string $country = null): array
$full_name = (string)$town['display_name'];
}

$results[] = array(
$results[] = [
'full_name' => $full_name,
'latitude' => (string)$town['lat'],
'longitude' => (string)$town['lon']
);
];
}
} else {
Analog::log(
Expand Down
4 changes: 2 additions & 2 deletions tests/GaletteMaps/tests/units/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testCoordinates(): void
$this->assertSame([], $coords->listCoords());

//set coordinates for member one
$this->assertTrue($coords->setCoords($member->id, 50.362038,3.472998));
$this->assertTrue($coords->setCoords($member->id, 50.362038, 3.472998));
$this->assertEquals(
[
'id_adh' => $member->id,
Expand All @@ -79,7 +79,7 @@ public function testCoordinates(): void
);

//update coordinates for member one
$this->assertTrue($coords->setCoords($member->id, 51.362038,3.572998));
$this->assertTrue($coords->setCoords($member->id, 51.362038, 3.572998));

//remove coordinates for member one
$this->assertTrue($coords->removeCoords($member->id));
Expand Down
2 changes: 1 addition & 1 deletion tests/TestsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
$basepath = '../../../galette/';

include_once '../../../tests/TestsBootstrap.php';
require_once __DIR__ . '/../_config.inc.php';
require_once __DIR__ . '/../_config.inc.php';