Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding php-cs-fixer #14

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 22 additions & 0 deletions .github/workflows/test-lint-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

name: Tests 🎳

on:
push:
# paths:
# - '**.php'
pull_request:
# paths:
# - '**.php'

jobs:
test-php-cs-fixer:
name: "PHP-CS-Fixer"
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@master

- uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist --allow-risky=yes --dry-run --diff -- mapBuilder
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
node_modules/

.php_cs.caches
52 changes: 52 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(array(
__DIR__.'/mapBuilder',
))
;

return PhpCsFixer\Config::create()
->setCacheFile(__DIR__.'/.php_cs.cache')
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@PhpCsFixer' => true,
'array_syntax' => array('syntax'=>'long'),
'method_argument_space'=> ['on_multiline' => 'ensure_fully_multiline'],
'new_with_braces'=> true,
'no_whitespace_in_blank_line'=> true,
'no_whitespace_before_comma_in_array'=> true,
'no_useless_return' => true,
'no_unneeded_final_method'=> true,
'no_unset_cast' => false,
'no_leading_import_slash'=> true,
'no_leading_namespace_whitespace'=> true,
'no_extra_blank_lines'=> true,
'no_empty_statement'=> true,
'no_empty_comment'=> true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => false,
'phpdoc_var_without_name' => true,
'phpdoc_types' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_add_missing_param_annotation' => true,
'protected_to_private' => false,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false,
'simple_to_complex_string_variable' => false,
'standardize_not_equals' => true,
'standardize_increment' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style'=>array(
'always_move_variable' => false,
'equal' => false,
'identical' => false,
'less_and_greater' => null,
)
])
->setFinder($finder)
;
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
php-cs-fixer-test:
php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes --dry-run --diff

php-cs-fixer-apply:
php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes
77 changes: 38 additions & 39 deletions mapBuilder/classes/listBaseLayer.class.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
<?php
<?php

require_once (JELIX_LIB_PATH.'forms/jFormsDatasource.class.php');
require_once JELIX_LIB_PATH.'forms/jFormsDatasource.class.php';

class listBaseLayer implements jIFormsDatasource
{
protected $formId = 0;

protected $data = array();

function __construct($id)
{
$this->formId = $id;

$this->data = array(
'osmMapnik' => 'OSM Mapnik',
'osmStamenToner' => 'OSM Stamen Toner',
'osmCyclemap' => 'OSM Cyclemap',
'bingStreets' => 'Bing Streets',
'bingSatellite' => 'Bing Satellite',
'bingHybrid' => 'Bing Hybrid',
'ignTerrain' => 'IGN Terrain',
'ignStreets' => 'IGN Streets',
'ignSatellite' => 'IGN Satellite',
'ignCadastral' => 'IGN Cadastral',
'emptyBaselayer' => jLocale::get('view~dictionnary.baselayer.empty.title')
);
}

public function getData($form)
{
return ($this->data);
}

public function getLabel($key)
{
if(isset($this->data[$key]))
return $this->data[$key];
else
return null;
}

protected $formId = 0;

protected $data = array();

public function __construct($id)
{
$this->formId = $id;

$this->data = array(
'osmMapnik' => 'OSM Mapnik',
'osmStamenToner' => 'OSM Stamen Toner',
'osmCyclemap' => 'OSM Cyclemap',
'bingStreets' => 'Bing Streets',
'bingSatellite' => 'Bing Satellite',
'bingHybrid' => 'Bing Hybrid',
'ignTerrain' => 'IGN Terrain',
'ignStreets' => 'IGN Streets',
'ignSatellite' => 'IGN Satellite',
'ignCadastral' => 'IGN Cadastral',
'emptyBaselayer' => jLocale::get('view~dictionnary.baselayer.empty.title'),
);
}

public function getData($form)
{
return $this->data;
}

public function getLabel($key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
}

return null;
}
}
?>
53 changes: 26 additions & 27 deletions mapBuilder/classes/listRepositories.class.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
<?php
<?php

require_once (JELIX_LIB_PATH.'forms/jFormsDatasource.class.php');
require_once JELIX_LIB_PATH.'forms/jFormsDatasource.class.php';

class listRepositories implements jIFormsDatasource
{
protected $formId = 0;
protected $formId = 0;

protected $data = array();
protected $data = array();

function __construct($id)
{
$this->formId = $id;
public function __construct($id)
{
$this->formId = $id;

$repositories = array();
$repositories = array();

foreach (lizmap::getRepositoryList() as $repositoryName) {
$repository = lizmap::getRepository($repositoryName);
if( jAcl2::check('lizmap.repositories.view', $repository->getKey() )){
$repositories[$repository->getKey()] = $repository->getData('label');
foreach (lizmap::getRepositoryList() as $repositoryName) {
$repository = lizmap::getRepository($repositoryName);
if (jAcl2::check('lizmap.repositories.view', $repository->getKey())) {
$repositories[$repository->getKey()] = $repository->getData('label');
}
}
}

$this->data = $repositories;
}
$this->data = $repositories;
}

public function getData($form)
{
return ($this->data);
}
public function getData($form)
{
return $this->data;
}

public function getLabel($key)
{
if(isset($this->data[$key]))
return $this->data[$key];
else
return null;
}
public function getLabel($key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
}

return null;
}
}
?>
41 changes: 21 additions & 20 deletions mapBuilder/classes/mapBuilderView.listener.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
<?php
class mapBuilderViewListener extends jEventListener{

function onmainviewGetMaps ($event) {
class mapBuilderViewListener extends jEventListener
{
public function onmainviewGetMaps($event)
{

// Access control
if( jAcl2::check("mapBuilder.access") ){
if (jAcl2::check('mapBuilder.access')) {
$name = jLocale::get('mapBuilder~default.app.name');
$access = jLocale::get('mapBuilder~default.app.access');
$description = jLocale::get('mapBuilder~default.app.description');

// Default extent is metropolitan France in EPSG:3857.
$extent = '-517635.63,6742470.88,1013007.37,4957918.98';
// Read mapBuilder configuration
$readConfigPath = parse_ini_file(jApp::configPath('mapBuilder.ini.php'), True);
$readConfigPath = parse_ini_file(jApp::configPath('mapBuilder.ini.php'), true);
// Get original extent from ini file if set
if(array_key_exists('extent', $readConfigPath)){
if (array_key_exists('extent', $readConfigPath)) {
// Reproject extent in ini file from EPSG:4326 to EPSG:3857.
$proj4 = new Proj4php();
$sourceProj = new Proj4phpProj('EPSG:4326', $proj4);
$destProj = new Proj4phpProj('EPSG:3857', $proj4);
$destProj = new Proj4phpProj('EPSG:3857', $proj4);

$extentArraySource = explode(",", $readConfigPath['extent']);
$extentArraySource = explode(',', $readConfigPath['extent']);

// Is extent valid ?
if(count($extentArraySource) == 4 && $extentArraySource === array_filter($extentArraySource, 'is_numeric')){
if (count($extentArraySource) == 4 && $extentArraySource === array_filter($extentArraySource, 'is_numeric')) {
// Cast as float
$extentArraySource = array_map('floatval', $extentArraySource);

// Handle WGS84 bounds
$sourceMinPt = new proj4phpPoint( max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06) );
$sourceMaxPt = new proj4phpPoint( min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06) );
$sourceMinPt = new proj4phpPoint(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06));
$sourceMaxPt = new proj4phpPoint(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06));

try {
$destMinPt = $proj4->transform($sourceProj,$destProj,$sourceMinPt);
$destMaxPt = $proj4->transform($sourceProj,$destProj,$sourceMaxPt);

$extent = implode(", ", array( $destMinPt->x, $destMinPt->y, $destMaxPt->x, $destMaxPt->y ));
$destMinPt = $proj4->transform($sourceProj, $destProj, $sourceMinPt);
$destMaxPt = $proj4->transform($sourceProj, $destProj, $sourceMaxPt);

$extent = implode(', ', array($destMinPt->x, $destMinPt->y, $destMaxPt->x, $destMaxPt->y));
} catch (Exception $e) {
// Max extent in EPSG:3857
$extent = "-20026376.39,-20048966.10,20026376.39,20048966.10";
$extent = '-20026376.39,-20048966.10,20026376.39,20048966.10';
}
}else{
jMessage::add(jLocale::get("mapBuilder~default.extent.value.error"), 'error');
$extent = jLocale::get("mapBuilder~default.extent.value.error");
} else {
jMessage::add(jLocale::get('mapBuilder~default.extent.value.error'), 'error');
$extent = jLocale::get('mapBuilder~default.extent.value.error');
}
}

$illustration = jApp::urlBasePath().'themes/'.jApp::config()->theme.'/css/img/250x250_mappemonde.jpg';

jClasses::inc('lizmapMainViewItem');
Expand All @@ -64,7 +65,7 @@ function onmainviewGetMaps ($event) {
'_map_builder_rep',
'map'
);
$event->add( $mrep );
$event->add($mrep);
}
}
}
Loading