Skip to content

Commit

Permalink
Merge pull request #27 from akeneo-labs/jml-wip
Browse files Browse the repository at this point in the history
Fix coding standards
  • Loading branch information
jmleroux committed Mar 25, 2016
2 parents 97409bb + 16f695e commit 0de86c3
Show file tree
Hide file tree
Showing 30 changed files with 108 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ php:
- 7.0
- hhvm

env:
- COMPOSER_FLAGS='--prefer-dist'

matrix:
fast_finish: true
allow_failures:
Expand All @@ -21,9 +24,10 @@ matrix:
- php: 5.4
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: DEPENDENCIES=dev
env: COMPOSER_FLAGS='--prefer-dist' DEPENDENCIES=dev

before_install:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-rm xdebug.ini; fi
- composer self-update
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This component is designed to extract data from spreadsheets, while being easy o

The current version of the spreadsheet parser works with csv and xlsx files.

[![Travis Build Status](https://travis-ci.org/akeneo-labs/spreadsheet-parser.svg?branch=master)](https://travis-ci.org/akeneo-labs/spreadsheet-parser)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/akeneo-labs/spreadsheet-parser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/akeneo-labs/spreadsheet-parser/?branch=master)

Installing the package
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"name": "Matthieu Viel",
"email": "[email protected]",
"homepage": "http://akeneo.com"
},
{
"name": "JM Leroux",
"email": "[email protected]"
}
],
"require": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ class RowIteratorFactorySpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith(
'spec\Akeneo\Component\SpreadsheetParser\Csv\StubRowIterator'
);
$this->beConstructedWith('spec\Akeneo\Component\SpreadsheetParser\Csv\StubRowIterator');
}

public function it_is_initializable()
{
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\RowIteratorFactory');
}

public function it_creates_row_iterators(
) {
public function it_creates_row_iterators()
{
$iterator = $this->create('path', ['options']);
$iterator->getPath()->shouldReturn('path');
$iterator->getOptions()->shouldReturn(['options']);
Expand All @@ -30,15 +28,18 @@ class StubRowIterator
{
protected $path;
protected $options;

public function __construct($path, $options)
{
$this->path = $path;
$this->options = $options;
}

public function getOptions()
{
return $this->options;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RowIteratorSpec extends ObjectBehavior
protected $values = [
1 => ['value', 'enclosed value', '15'],
2 => ['', 'value2', ''],
3 => ['é', 'è', '']
3 => ['é', 'è', '']
];

public function it_is_initializable()
Expand All @@ -20,9 +20,9 @@ public function it_is_initializable()

public function it_parses_csv_files()
{
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv' , []);
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv', []);
$this->rewind();
foreach ($this->values as $i=>$row) {
foreach ($this->values as $i => $row) {
$this->key()->shouldReturn($i);
$this->valid()->shouldReturn(true);
$this->current()->shouldReturn($row);
Expand All @@ -33,7 +33,7 @@ public function it_parses_csv_files()

public function it_can_be_rewinded()
{
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv' , []);
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv', []);
$this->rewind();
$this->current()->shouldReturn($this->values[1]);
$this->next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

class SpreadsheetLoaderSpec extends ObjectBehavior
{
public function let(
RowIteratorFactory $rowIteratorFactory
) {
public function let(RowIteratorFactory $rowIteratorFactory)
{
$this->beConstructedWith(
$rowIteratorFactory,
'spec\Akeneo\Component\SpreadsheetParser\Csv\StubSpreadsheet',
Expand All @@ -22,9 +21,8 @@ public function it_is_initializable()
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\SpreadsheetLoader');
}

public function it_creates_spreadsheet_objects(
RowIteratorFactory $rowIteratorFactory
) {
public function it_creates_spreadsheet_objects(RowIteratorFactory $rowIteratorFactory)
{
$spreadsheet = $this->open('path');
$spreadsheet->getPath()->shouldReturn('path');
$spreadsheet->getSheetName()->shouldReturn('sheet');
Expand All @@ -37,20 +35,24 @@ class StubSpreadsheet
protected $rowIteratorFactory;
protected $sheetName;
protected $path;

public function __construct($rowIteratorFactory, $sheetName, $path)
{
$this->rowIteratorFactory = $rowIteratorFactory;
$this->sheetName = $sheetName;
$this->path = $path;
}

public function getRowIteratorFactory()
{
return $this->rowIteratorFactory;
}

public function getSheetName()
{
return $this->sheetName;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function let(
SpreadsheetLoaderInterface $loader,
SpreadsheetLoaderInterface $otherLoader,
SpreadsheetInterface $spreadsheet
) {
)
{
$this->addLoader('extension', $loader)->addLoader('other_extension', $otherLoader);
$loader->open('file.extension')->willReturn($spreadsheet);
}
Expand All @@ -24,7 +25,8 @@ public function it_is_initializable()

public function it_uses_the_loader_corresponding_to_the_file_extension(
SpreadsheetInterface $spreadsheet
) {
)
{
$this->open('file.extension')->shouldReturn($spreadsheet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public function it_loads_files()
class StubArchive
{
protected $path;

public function __construct($path)
{
$this->path = $path;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public function it_loads_relationships()
class StubRelationships
{
protected $path;

public function __construct($path)
{
$this->path = $path;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class StubRowIterator
protected $valueTransformer;
protected $path;
protected $options;

public function __construct($rowBuilderFactory, $columnIndexTransformer, $valueTransformer, $path, $options)
{
$this->rowBuilderFactory = $rowBuilderFactory;
Expand All @@ -52,22 +53,27 @@ public function __construct($rowBuilderFactory, $columnIndexTransformer, $valueT
$this->path = $path;
$this->options = $options;
}

public function getPath()
{
return $this->path;
}

public function getValueTransformer()
{
return $this->valueTransformer;
}

public function getRowBuilderFactory()
{
return $this->rowBuilderFactory;
}

public function getColumnIndexTransformer()
{
return $this->columnIndexTransformer;
}

public function getOptions()
{
return $this->options;
Expand Down
24 changes: 13 additions & 11 deletions spec/Akeneo/Component/SpreadsheetParser/Xlsx/RowIteratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function let(
ColumnIndexTransformer $columnIndexTransformer,
ValueTransformer $valueTransformer,
RowBuilder $rowBuilder
) {
)
{
$startWith = function ($startString) {
return function ($string) use ($startString) {
return $startString === substr($string, 0, strlen($startString));
Expand Down Expand Up @@ -53,11 +54,12 @@ function () use (&$row) {
__DIR__ . '/fixtures/sheet.xml',
[]
);
$valueTransformer->transform(Argument::type('string'),Argument::type('string'),Argument::type('string'))->will(
function ($args) {
return $args;
}
);
$valueTransformer->transform(Argument::type('string'), Argument::type('string'), Argument::type('string'))
->will(
function ($args) {
return $args;
}
);
}

public function it_is_initializable()
Expand All @@ -68,9 +70,9 @@ public function it_is_initializable()
public function it_iterates_through_rows()
{
$values = [
1 => [0 => ['0', 's','0'], 1 => ['1', 's','0'], 3 => ['', '','1']],
2 => [0 => ['2', 's','0'], 1 => ['3', 's','0'], 2 => ['4', 's','0']],
4 => [0 => ['5', 'n','0'], 2 => ['6', 'n','1']],
1 => [0 => ['0', 's', '0'], 1 => ['1', 's', '0'], 3 => ['', '', '1']],
2 => [0 => ['2', 's', '0'], 1 => ['3', 's', '0'], 2 => ['4', 's', '0']],
4 => [0 => ['5', 'n', '0'], 2 => ['6', 'n', '1']],
];

$this->rewind();
Expand All @@ -88,12 +90,12 @@ public function it_can_be_rewinded()
{
$this->rewind();
$this->valid()->shouldReturn(true);
$this->current()->shouldReturn([0 => ['0', 's','0'], 1 => ['1', 's','0'], 3 => ['', '','1']]);
$this->current()->shouldReturn([0 => ['0', 's', '0'], 1 => ['1', 's', '0'], 3 => ['', '', '1']]);
$this->key()->shouldReturn(1);
$this->next();
$this->rewind();
$this->valid()->shouldReturn(true);
$this->current()->shouldReturn([0 => ['0', 's','0'], 1 => ['1', 's','0'], 3 => ['', '','1']]);
$this->current()->shouldReturn([0 => ['0', 's', '0'], 1 => ['1', 's', '0'], 3 => ['', '', '1']]);
$this->key()->shouldReturn(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public function it_loads_shared_strings()
class StubSharedStrings
{
protected $path;

public function __construct($path)
{
$this->path = $path;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public function it_loads_shared_strings()
class StubStyles
{
protected $path;

public function __construct($path)
{
$this->path = $path;
}

public function getPath()
{
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class StubValueTransformer
protected $dateTransformer;
protected $sharedStrings;
protected $styles;

public function __construct($dateTransformer, $sharedStrings, $styles)
{
$this->sharedStrings = $sharedStrings;
$this->dateTransformer = $dateTransformer;
$this->styles = $styles;
}

public function getSharedStrings()
{
return $this->sharedStrings;
Expand All @@ -51,6 +53,7 @@ public function getDateTransformer()
{
return $this->dateTransformer;
}

public function getStyles()
{
return $this->styles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace spec\Akeneo\Component\SpreadsheetParser\Xlsx;

use PhpSpec\ObjectBehavior;
use Akeneo\Component\SpreadsheetParser\Xlsx\Relationships;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class WorksheetListReaderSpec extends ObjectBehavior
{
Expand Down
2 changes: 1 addition & 1 deletion src/Csv/SpreadsheetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(RowIteratorFactory $rowIteratorFactory, $spreadsheet
/**
* {@inheritdoc}
*/
public function open($path)
public function open($path, $type = null)
{
return new $this->spreadsheetClass(
$this->rowIteratorFactory,
Expand Down
7 changes: 4 additions & 3 deletions src/SpreadsheetLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ interface SpreadsheetLoaderInterface
* Spreadsheet objects are cached, and will be read only once
*
* @param string $path
*
* @return Spreadsheet
* @param null $type
*
* @return SpreadsheetInterface
*/
public function open($path);
public function open($path, $type = null);
}
4 changes: 2 additions & 2 deletions src/Xlsx/ColumnIndexTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function transform($name)
$number = -1;

foreach (str_split($name) as $chr) {
$digit = ord($chr) -65;
$digit = ord($chr) - 65;
if ($digit < 0) {
break;
}
$number = ($number+1) * 26 + $digit;
$number = ($number + 1) * 26 + $digit;
}

return $number;
Expand Down
Loading

0 comments on commit 0de86c3

Please sign in to comment.