Skip to content

Commit

Permalink
Experiment to replace the large "unstructured" array of Excel functio…
Browse files Browse the repository at this point in the history
…n signature definitions with a structured collection of Value Objects to see what affect it has on memory usage and speed.

This isn't a perfect implementation yet: but it's enough to take a look at the memory usage and speed.
  • Loading branch information
MarkBaker committed Mar 27, 2022
1 parent 8885c4e commit 3dff948
Show file tree
Hide file tree
Showing 511 changed files with 17,317 additions and 2,540 deletions.
4 changes: 4 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
<rule ref="PSR12">
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
</rule>

<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>*/src/PhpSpreadsheet/Calculation/Engine/Functions/*</exclude-pattern>
</rule>
</ruleset>
5 changes: 1 addition & 4 deletions bin/generate-locales
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use PhpOffice\PhpSpreadsheetInfra\LocaleGenerator;
require_once 'vendor/autoload.php';

try {
$phpSpreadsheetFunctionsProperty = (new ReflectionClass(Calculation::class))
->getProperty('phpSpreadsheetFunctions');
$phpSpreadsheetFunctionsProperty->setAccessible(true);
$phpSpreadsheetFunctions = $phpSpreadsheetFunctionsProperty->getValue();
$phpSpreadsheetFunctions = Calculation::getInstance()->getFunctions();

$localeGenerator = new LocaleGenerator(
realpath(__DIR__ . '/../src/PhpSpreadsheet/Calculation/locale/'),
Expand Down
8 changes: 6 additions & 2 deletions infra/LocaleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheetInfra;

use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Engine\ExcelFunctions;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -37,6 +38,9 @@ class LocaleGenerator
*/
protected $translationBaseFolder;

/**
* @var ExcelFunctions
*/
protected $phpSpreadsheetFunctions;

/**
Expand Down Expand Up @@ -67,7 +71,7 @@ class LocaleGenerator
public function __construct(
string $translationBaseFolder,
string $translationSpreadsheetName,
array $phpSpreadsheetFunctions,
ExcelFunctions $phpSpreadsheetFunctions,
bool $verbose = false
) {
$this->translationBaseFolder = $translationBaseFolder;
Expand Down Expand Up @@ -146,7 +150,7 @@ protected function buildFunctionsFileForLocale($column, $locale): void
$translationValue = $translationCell->getValue();
if ($this->isFunctionCategoryEntry($translationCell)) {
$this->writeFileSectionHeader($functionFile, "{$translationValue} ({$functionName})");
} elseif (!array_key_exists($functionName, $this->phpSpreadsheetFunctions)) {
} elseif (!$this->phpSpreadsheetFunctions->isRecognisedExcelFunction($functionName)) {
$this->log("Function {$functionName} is not defined in PhpSpreadsheet");
} elseif (!empty($translationValue)) {
$functionTranslation = "{$functionName} = {$translationValue}" . self::EOL;
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$phpSpreadsheetFunctions has no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:\\$returnArrayAsType has no type specified\\.$#"
count: 1
Expand Down
Loading

0 comments on commit 3dff948

Please sign in to comment.