Skip to content

Commit

Permalink
phpcs: add config
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Jun 6, 2018
1 parent b4c5fa3 commit fd2c797
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
1 change: 0 additions & 1 deletion library/Fileshipper/ProvidedHook/Director/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ protected static function addXslxElements(QuickForm $form, $filename)
/** @var \Icinga\Module\Director\Forms\ImportSourceForm $form */
$addressing = $form->getSentOrObjectSetting('worksheet_addressing');
switch ($addressing) {

case 'by_name':
$file = static::loadXslxFile($filename);
$names = $file->getSheetNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function listFiles($folder, $extensions)
$fileList = [];
$start = strlen($folder) + 1;

foreach($files as $file) {
foreach ($files as $file) {
foreach ($file as $f) {
$fileList[] = substr($f, $start);
}
Expand Down
24 changes: 12 additions & 12 deletions library/Fileshipper/Xlsx/Workbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Workbook
{
// XML schemas
const SCHEMA_OFFICEDOCUMENT = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument';
const SCHEMA_RELATIONSHIP = 'http://schemas.openxmlformats.org/package/2006/relationships';
const SCHEMA_OFFICEDOCUMENT_RELATIONSHIP = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
const SCHEMA_SHAREDSTRINGS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings';
const SCHEMA_RELATIONSHIP = 'http://schemas.openxmlformats.org/package/2006/relationships';
const SCHEMA_SHAREDSTRINGS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings';
const SCHEMA_WORKSHEETRELATION = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet';

protected static $zipErrors = [
Expand Down Expand Up @@ -81,7 +81,7 @@ protected function getZipErrorString($errorCode)
protected function extractFile($name)
{
$data = $this->zip->getFromName($name);
if($data === false) {
if ($data === false) {
throw new RuntimeException(sprintf(
"File %s does not exist in the Excel file",
$name
Expand All @@ -108,7 +108,7 @@ protected function getPackageRelationships()
protected function getMainDocumentRelation()
{
if ($this->mainRelation === null) {
foreach($this->getPackageRelationships() as $relation) {
foreach ($this->getPackageRelationships() as $relation) {
if ($relation['Type'] == self::SCHEMA_OFFICEDOCUMENT) {
$this->mainRelation = $relation;
break;
Expand Down Expand Up @@ -181,7 +181,7 @@ protected function parse()
$this->extractFile($workbookDir . $relation['Target'])
);

foreach($sharedStringsXML->si as $val) {
foreach ($sharedStringsXML->si as $val) {
if (isset($val->t)) {
$this->sharedStrings[] = (string)$val->t;
} elseif (isset($val->r)) {
Expand Down Expand Up @@ -210,8 +210,8 @@ protected function parse()
// returns an array of sheet names, indexed by sheetId
public function getSheetNames()
{
$res = array();
foreach($this->sheetInfo as $sheetName => $info) {
$res = [];
foreach ($this->sheetInfo as $sheetName => $info) {
$res[$info['sheetId']] = $sheetName;
// $res[$info['rid']] = $sheetName;
}
Expand All @@ -237,7 +237,7 @@ public function getSheet($sheet)
{
if (is_numeric($sheet)) {
$sheet = $this->getSheetNameById($sheet);
} elseif(!is_string($sheet)) {
} elseif (!is_string($sheet)) {
throw new RuntimeException("Sheet must be a string or a sheet Id");
}
if (!array_key_exists($sheet, $this->sheets)) {
Expand All @@ -259,7 +259,7 @@ public function getSheetByName($name)
public function enumRidNames()
{
$res = [];
foreach($this->sheetInfo as $name => $info) {
foreach ($this->sheetInfo as $name => $info) {
$res[$name] = $name;
}

Expand All @@ -268,8 +268,8 @@ public function enumRidNames()

public function getSheetNameById($sheetId)
{
foreach($this->sheetInfo as $sheetName => $sheetInfo) {
if($sheetInfo['sheetId'] === $sheetId) {
foreach ($this->sheetInfo as $sheetName => $sheetInfo) {
if ($sheetInfo['sheetId'] === $sheetId) {
return $sheetName;
}
}
Expand All @@ -286,7 +286,7 @@ public function getFirstSheetName()
throw new RuntimeException('Workbook contains no sheets');
}

foreach($this->sheetInfo as $sheetName => $sheetInfo) {
foreach ($this->sheetInfo as $sheetName => $sheetInfo) {
return $sheetName;
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/Fileshipper/Xlsx/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function parseData($sheetData)
$rowNum = (int) $row['r'];
if ($rowNum != ($curR + 1)) {
$missingRows = $rowNum - ($curR + 1);
for($i=0; $i < $missingRows; $i++) {
for ($i = 0; $i < $missingRows; $i++) {
$rows[$curR] = array_pad([], $this->colCount, null);
$curR++;
}
Expand Down Expand Up @@ -201,7 +201,7 @@ protected function parseCellValue($cell)
$value = (string)$cell->v;
if ($value === '0') {
$value = false;
} else if ($value == '1') {
} elseif ($value == '1') {
$value = true;
} else {
$value = (bool) $cell->v;
Expand Down
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>Sniff our code</description>

<file>run.php</file>
<file>library/</file>

<arg value="wps"/>
<arg name="colors"/>
<arg name="report-width" value="auto"/>
<arg name="report-full"/>
<arg name="report-gitblame"/>
<arg name="report-summary"/>
<arg name="encoding" value="UTF-8"/>

<rule ref="PSR2"/>
</ruleset>

0 comments on commit fd2c797

Please sign in to comment.