Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Dec 6, 2023
1 parent 5c565ec commit 2692620
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ $mixer = new \AnourValar\Office\Mixer();
$mixer($documentA, $documentB)->saveAs('generated_document.xlsx');
```

### Access the PhpSpreadsheetDriver directly (default driver)

```php
(new \AnourValar\Office\SheetsService())
->hookBefore(function (\AnourValar\Office\Drivers\PhpSpreadsheetDriver $driver, array &$data) {
$spreadsheet = $driver->spreadsheet;

// @see \PhpOffice\PhpSpreadsheet\Spreadsheet
$spreadsheet->createSheet()->setTitle('Foo Bar'); // adding a new Worksheet
})
->generate('template.xlsx', [])
->saveAs('generated_document.xlsx');
```


## Generate a document from an DOCX (Word) template

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.26",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^5.17"
},
"autoload": {
"psr-4": {"AnourValar\\Office\\": "src/"}
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<file>src</file>
<file>tests</file>
<exclude-pattern>src/resources</exclude-pattern>

<!-- Show progress of the run -->
<arg value= "p"/>
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ parameters:
- '#Access to an undefined property AnourValar\\Office\\Drivers\\MixInterface\:\:\$spreadsheet#'
- '#Call to an undefined method AnourValar\\Office\\Drivers\\MixInterface\:\:sheet\(\)#'


excludePaths:


checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
checkAlwaysTrueInstanceof: true
Expand Down
38 changes: 38 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
findUnusedPsalmSuppress="true"
findUnusedVariablesAndParams="true"
>
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<UnusedClosureParam errorLevel="suppress" />
<PossiblyUnusedMethod errorLevel="suppress" />
<UnusedClass errorLevel="suppress" />
<UndefinedClass errorLevel="suppress" />
<PossiblyUnusedParam errorLevel="suppress" />
<PossiblyUnusedProperty errorLevel="suppress" />
<PossiblyUnusedReturnValue errorLevel="suppress" />
<MissingTemplateParam errorLevel="suppress" />
<UnsupportedPropertyReferenceUsage errorLevel="suppress" />
</issueHandlers>

<forbiddenFunctions>
<function name="var_dump" />
<function name="dd" />
<function name="dump" />
</forbiddenFunctions>
</psalm>
1 change: 1 addition & 0 deletions src/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __toString(): string

/**
* @return void
* @psalm-suppress InaccessibleProperty
*/
public function __destruct()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Drivers/PhpSpreadsheetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function sheet(): \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
/**
* {@inheritDoc}
* @see \AnourValar\Office\Drivers\GridInterface::create()
* @psalm-suppress InaccessibleProperty
*/
public function create(): self
{
Expand All @@ -60,6 +61,7 @@ public function create(): self
/**
* {@inheritDoc}
* @see \AnourValar\Office\Drivers\LoadInterface::load()
* @psalm-suppress InaccessibleProperty
*/
public function load(string $file, \AnourValar\Office\Format $format): self
{
Expand Down
1 change: 1 addition & 0 deletions src/Drivers/ZipDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function create(): self
/**
* {@inheritDoc}
* @see \AnourValar\Office\Drivers\LoadInterface::load()
* @psalm-suppress InaccessibleProperty
*/
public function load(string $file, \AnourValar\Office\Format $format): self
{
Expand Down
1 change: 1 addition & 0 deletions src/GridService.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function hookAfter(?\Closure $closure): self
* @param mixed $totalRange
* @param mixed $columns
* @return \Closure
* @psalm-suppress UnusedForeachValue
*/
protected function getGenerator(
\AnourValar\Office\Drivers\GridInterface $driver,
Expand Down
3 changes: 2 additions & 1 deletion src/Sheets/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function schema(array $values, array $data, array $mergeCells): SchemaMap
protected function parseValues(array $values, &$lastColumn): array
{
$lastColumn = 'A';
foreach ($values as $row => &$columns) {
foreach ($values as &$columns) {
$currLastColumn = array_key_last($columns);
if ($this->isColumnLE($lastColumn, $currLastColumn)) {
$lastColumn = $currLastColumn;
Expand Down Expand Up @@ -179,6 +179,7 @@ function ($patterns) use ($data) {
* @param \AnourValar\Office\Sheets\SchemaMapper $schema
* @param string $lastColumn
* @return array
* @psalm-suppress UnusedForeachValue
*/
protected function calculateDataSchema(
array &$values,
Expand Down
1 change: 1 addition & 0 deletions tests/GridServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ public function test_generate_statistic_without_headers_with_shift()

/**
* @return \AnourValar\Office\Drivers\GridInterface
* @psalm-suppress UnusedForeachValue
*/
protected function getDriver(): \AnourValar\Office\Drivers\GridInterface
{
Expand Down

0 comments on commit 2692620

Please sign in to comment.