Skip to content

Commit

Permalink
Merge pull request #1 from PHPOffice/phpCSFixer
Browse files Browse the repository at this point in the history
Github Action : PHPCSFixer
  • Loading branch information
Progi1984 committed Sep 21, 2023
2 parents 1da42eb + df302a6 commit a597340
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 82 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ on:
pull_request:

jobs:
php-cs-fixer:
name: PHP CS Fixer
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: xml

- uses: actions/checkout@v2

- name: Validate composer config
run: composer validate --strict

- name: Composer Install
run: composer global require friendsofphp/php-cs-fixer

- name: Add environment path
run: export PATH="$PATH:$HOME/.composer/vendor/bin"

- name: Run PHPCSFixer
run: php-cs-fixer fix --dry-run --diff

phpunit:
name: PHPUnit
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.php_cs.cache
.phpunit.cache
.phpunit.result.cache
composer.lock
Expand Down
45 changes: 45 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

$config = new PhpCsFixer\Config();

$config
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_indentation' => true,
'cast_spaces' => [
'space' => 'single',
],
'combine_consecutive_issets' => true,
'concat_space' => [
'spacing' => 'one',
],
'error_suppression' => [
'mute_deprecation_error' => false,
'noise_remaining_usages' => false,
'noise_remaining_usages_exclude' => [],
],
'function_to_constant' => false,
'global_namespace_import' => true,
'method_chaining_indentation' => true,
'no_alias_functions' => false,
'no_superfluous_phpdoc_tags' => false,
'non_printable_character' => [
'use_escape_sequences_in_strings' => true,
],
'phpdoc_align' => [
'align' => 'left',
],
'phpdoc_summary' => false,
'protected_to_private' => false,
'self_accessor' => false,
'yoda_style' => false,
'single_line_throw' => false,
'no_alias_language_construct_call' => false,
])
->getFinder()
->in(__DIR__)
->exclude('vendor');

return $config;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
"require": {
"php": "^7.1|^8.0",
"ext-xml": "*"
"ext-xml": "*",
"friendsofphp/php-cs-fixer": "^2.1"
},
"require-dev": {
"phpunit/phpunit": ">=7.0"
Expand Down
6 changes: 3 additions & 3 deletions src/Math/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ abstract class AbstractElement
* @var string
*/
protected $parent;

public function setParent($parent): self
{
$this->parent = $parent;

return $this;
}

public function getParent()
{
return $this->parent;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/AbstractGroupElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function getElements(): array
{
return $this->elements;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Fraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function setNumerator(AbstractElement $element): self

return $this;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public function getValue(): string
{
return $this->value;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Numeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public function getValue(): float
{
return $this->value;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public function getValue(): string
{
return $this->value;
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class Row extends AbstractGroupElement
{
}
}
2 changes: 1 addition & 1 deletion src/Math/Element/Superscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function setSuperscript(AbstractElement $element): self

return $this;
}
}
}
4 changes: 3 additions & 1 deletion src/Math/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Math

/**
* @param Element\AbstractElement $element
*
* @return self
*/
public function add(Element\AbstractElement $element): self
Expand All @@ -23,6 +24,7 @@ public function add(Element\AbstractElement $element): self

/**
* @param Element\AbstractElement $element
*
* @return self
*/
public function remove(Element\AbstractElement $element): self
Expand All @@ -42,4 +44,4 @@ public function getElements(): array
{
return $this->elements;
}
}
}
13 changes: 8 additions & 5 deletions src/Math/Reader/MathML.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use DOMElement;
use DOMXPath;
use Exception;
use PhpOffice\Math\Math;
use PhpOffice\Math\Element;
use PhpOffice\Math\Math;

class MathML implements ReaderInterface
{
Expand Down Expand Up @@ -66,6 +66,7 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
->setNumerator($this->getElement($nodeList->item(0)))
->setDenominator($this->getElement($nodeList->item(1)));
}

return $element;
case 'mi':
return new Element\Identifier($nodeValue);
Expand All @@ -75,13 +76,14 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
if (empty($nodeValue)) {
$nodeList = $this->xpath->query('*', $nodeElement);
if (
$nodeList->length == 1
$nodeList->length == 1
&& $nodeList->item(0)->nodeName == 'mchar'
&& $nodeList->item(0)->hasAttribute('name')
) {
$nodeValue = $nodeList->item(0)->getAttribute('name');
}
}

return new Element\Operator($nodeValue);
case 'mrow':
return new Element\Row();
Expand All @@ -93,13 +95,14 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
->setBase($this->getElement($nodeList->item(0)))
->setSuperscript($this->getElement($nodeList->item(1)));
}

return $element;
default:
default:
throw new Exception(sprintf(
'%s : The tag `%s` is not implemented',
__METHOD__,
__METHOD__,
$nodeElement->nodeName
));
}
}
}
}
16 changes: 9 additions & 7 deletions src/Math/Reader/OfficeMathML.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use DOMElement;
use DOMXPath;
use Exception;
use PhpOffice\Math\Math;
use PhpOffice\Math\Element;
use PhpOffice\Math\Math;

class OfficeMathML implements ReaderInterface
{
Expand Down Expand Up @@ -44,8 +44,8 @@ public function read(string $content): ?Math
}

/**
* @link https://devblogs.microsoft.com/math-in-office/officemath/
* @link https://learn.microsoft.com/fr-fr/archive/blogs/murrays/mathml-and-ecma-math-omml
* @see https://devblogs.microsoft.com/math-in-office/officemath/
* @see https://learn.microsoft.com/fr-fr/archive/blogs/murrays/mathml-and-ecma-math-omml
*/
protected function parseNode(?DOMElement $nodeRowElement, $parent): void
{
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
}
}
// Denominator
$nodeDenominator= $this->xpath->query('m:den/m:r/m:t', $nodeElement);
$nodeDenominator = $this->xpath->query('m:den/m:r/m:t', $nodeElement);
if ($nodeDenominator->length == 1) {
$value = $nodeDenominator->item(0)->nodeValue;
if (is_numeric($value)) {
Expand All @@ -85,6 +85,7 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
$element->setDenominator(new Element\Identifier($value));
}
}

return $element;
case 'm:r':
$nodeText = $this->xpath->query('m:t', $nodeElement);
Expand All @@ -96,17 +97,18 @@ protected function getElement(DOMElement $nodeElement): Element\AbstractElement
if (is_numeric($value)) {
return new Element\Numeric($value);
}

return new Element\Identifier($value);
}
break;
case 'm:oMath':
return new Element\Row();
default:
default:
throw new Exception(sprintf(
'%s : The tag `%s` is not implemented',
__METHOD__,
__METHOD__,
$nodeElement->nodeName
));
}
}
}
}
2 changes: 1 addition & 1 deletion src/Math/Reader/ReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
interface ReaderInterface
{
public function read(string $content): ?Math;
}
}
15 changes: 9 additions & 6 deletions src/Math/Writer/MathML.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace PhpOffice\Math\Writer;

use Exception;
use PhpOffice\Math\Math;
use PhpOffice\Math\Element;
use PhpOffice\Math\Math;
use XMLWriter;

class MathML implements WriterInterface
Expand All @@ -14,6 +14,7 @@ class MathML implements WriterInterface

/**
* @param Math $math
*
* @return string
*/
public function write(Math $math): string
Expand Down Expand Up @@ -44,6 +45,7 @@ protected function writeElementItem(Element\AbstractElement $element): void
$this->writeElementItem($childElement);
}
$this->output->endElement();

return;
}

Expand All @@ -53,6 +55,7 @@ protected function writeElementItem(Element\AbstractElement $element): void
$this->writeElementItem($element->getBase());
$this->writeElementItem($element->getSuperscript());
$this->output->endElement();

return;
}

Expand All @@ -62,6 +65,7 @@ protected function writeElementItem(Element\AbstractElement $element): void
$this->writeElementItem($element->getNumerator());
$this->writeElementItem($element->getDenominator());
$this->output->endElement();

return;
}

Expand All @@ -80,12 +84,11 @@ protected function getElementTagName(Element\AbstractElement $element): string
if ($element instanceof Element\AbstractGroupElement) {
throw new Exception(sprintf(
'%s : The element of the class `%s` has no tag name',
__METHOD__,
__METHOD__,
get_class($element)
));
}

//
if ($element instanceof Element\Superscript) {
return 'msup';
}
Expand All @@ -101,11 +104,11 @@ protected function getElementTagName(Element\AbstractElement $element): string
if ($element instanceof Element\Operator) {
return 'mo';
}

throw new Exception(sprintf(
'%s : The element of the class `%s` has no tag name',
__METHOD__,
__METHOD__,
get_class($element)
));
}
}
}
Loading

0 comments on commit a597340

Please sign in to comment.