From 3c8970eaffe8250eba76377581cccedd2eb58802 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 2 May 2025 17:01:31 +0200 Subject: [PATCH 1/3] Galette 1.2.0 compatible --- _define.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_define.php b/_define.php index 4787b63..579db84 100644 --- a/_define.php +++ b/_define.php @@ -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 From a40bbd690053be8def6d6c5647cc4d82f4970515 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 2 May 2025 17:02:56 +0200 Subject: [PATCH 2/3] Add cs-fixer --- .github/workflows/ci-linux.yml | 6 +++ .php-cs-fixer.dist.php | 23 +++++++++++ .../Controllers/MapsController.php | 4 +- lib/GaletteMaps/Coordinates.php | 40 +++++++++---------- lib/GaletteMaps/NominatimTowns.php | 14 +++---- tests/GaletteMaps/tests/units/Coordinates.php | 4 +- tests/TestsBootstrap.php | 2 +- 7 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 6a46b3e..e679831 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -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 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..503e811 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,23 @@ +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) +; diff --git a/lib/GaletteMaps/Controllers/MapsController.php b/lib/GaletteMaps/Controllers/MapsController.php index 4dea87e..5953338 100644 --- a/lib/GaletteMaps/Controllers/MapsController.php +++ b/lib/GaletteMaps/Controllers/MapsController.php @@ -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 ( diff --git a/lib/GaletteMaps/Coordinates.php b/lib/GaletteMaps/Coordinates.php index 42cfc7d..1de9f08 100644 --- a/lib/GaletteMaps/Coordinates.php +++ b/lib/GaletteMaps/Coordinates.php @@ -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') { @@ -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 ); } @@ -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', @@ -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', '>=', @@ -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 ); @@ -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; } @@ -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] ); @@ -272,6 +272,6 @@ public function removeCoords(int $id): bool */ protected function getTableName(): string { - return MAPS_PREFIX . self::TABLE; + return MAPS_PREFIX . self::TABLE; } } diff --git a/lib/GaletteMaps/NominatimTowns.php b/lib/GaletteMaps/NominatimTowns.php index 84649d5..f29aff1 100644 --- a/lib/GaletteMaps/NominatimTowns.php +++ b/lib/GaletteMaps/NominatimTowns.php @@ -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; /** @@ -39,10 +37,10 @@ class NominatimTowns private Preferences $preferences; /** @var array */ - private array $query_options = array( + private array $query_options = [ 'format' => 'xml', 'addressdetails' => '1' - ); + ]; private string $uri = 'http://nominatim.openstreetmap.org/search'; /** @@ -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); } @@ -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; @@ -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( diff --git a/tests/GaletteMaps/tests/units/Coordinates.php b/tests/GaletteMaps/tests/units/Coordinates.php index 94696da..a57bb90 100644 --- a/tests/GaletteMaps/tests/units/Coordinates.php +++ b/tests/GaletteMaps/tests/units/Coordinates.php @@ -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, @@ -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)); diff --git a/tests/TestsBootstrap.php b/tests/TestsBootstrap.php index d7dbbc2..9b48101 100644 --- a/tests/TestsBootstrap.php +++ b/tests/TestsBootstrap.php @@ -29,4 +29,4 @@ $basepath = '../../../galette/'; include_once '../../../tests/TestsBootstrap.php'; -require_once __DIR__ . '/../_config.inc.php'; \ No newline at end of file +require_once __DIR__ . '/../_config.inc.php'; From 4adb97d408473547651d4043fdd83b343b0bffe0 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 2 May 2025 17:03:04 +0200 Subject: [PATCH 3/3] Fix scrutinizer config --- .scrutinizer.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 31e1e5c..08e4730 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -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: