Skip to content

Commit

Permalink
Upgrade php-cs-fixer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Dieleman committed Oct 24, 2023
1 parent c38cc20 commit a5ccab2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
/composer.lock
.idea

.php-cs-fixer.cache
30 changes: 17 additions & 13 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<?php

/**
* Adapted from config file distributed on php-cs-fixer vendor.
*/
return PhpCsFixer\Config::create()
->setRules(array(
$finder = (new PhpCsFixer\Finder())
->in(['src/', 'tests/'])
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'long'),
'combine_consecutive_unsets' => true,
'no_superfluous_phpdoc_tags' => false,
'phpdoc_separation' => false,
'phpdoc_types_order' => false,
'native_function_invocation' => false,
'single_line_throw' => false,
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => array(
'no_extra_blank_lines' => ['tokens' => [
'break', 'continue', 'extra', 'return', 'throw', 'use',
'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block',
),
]],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'psr4' => true,
))
'psr_autoloading' => true,
'visibility_required' => ['elements' => ['property', 'method']],
])
->setRiskyAllowed(true)
->setUsingCache(false)
// If we want to use cache for performance purposes, for now it's disabled
->setCacheFile('app/cache/.php_cs.cache')
->setFinder($finder)
;
26 changes: 11 additions & 15 deletions src/Fpdi/FdpiFacturx.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class FdpiFacturx extends \setasign\Fpdi\Fpdi
{
const ICC_PROFILE_PATH = __DIR__.'/icc/sRGB_v4_ICC_preference_displayclass.icc';

protected $files = array();
protected $metadata_descriptions = array();
protected $files = [];
protected $metadata_descriptions = [];
protected $file_spe_dictionnary_index = 0;
protected $description_index = 0;
protected $output_intent_index = 0;
protected $n_files;
protected $open_attachment_pane = false;
protected $pdf_metadata_infos = array();
protected $pdf_metadata_infos = [];

/**
* Set the PDF version.
Expand Down Expand Up @@ -73,7 +73,7 @@ public function Attach($file, $name = '', $desc = '', $relationship = 'Unspecifi
}
}
$mimetype = str_replace('/', '#2F', $mimetype);
$this->files[] = array('file' => $file, 'name' => $name, 'desc' => $desc, 'relationship' => $relationship, 'subtype' => $mimetype);
$this->files[] = ['file' => $file, 'name' => $name, 'desc' => $desc, 'relationship' => $relationship, 'subtype' => $mimetype];
}

/**
Expand Down Expand Up @@ -356,35 +356,31 @@ protected function _generate_metadata_string($date_type = 'created')
}

/**
* Replacement for utf8_encode which is deprecated since PHP 8.2
* Replacement for utf8_encode which is deprecated since PHP 8.2.
*
* @param string $s
*
* @return string
*/
public static function utf8_encode($s)
protected static function utf8_encode($s)
{
if (PHP_VERSION_ID < 80200)
{
if (\PHP_VERSION_ID < 80200) {
return utf8_encode($s);
}

if (function_exists('mb_convert_encoding'))
{
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($s, 'UTF-8', 'ISO-8859-1');
}

if (class_exists('UConverter'))
{
if (class_exists('UConverter')) {
return UConverter::transcode($s, 'UTF8', 'ISO-8859-1');
}

if (function_exists('iconv'))
{
if (function_exists('iconv')) {
return iconv('ISO-8859-1', 'UTF-8', $s);
}

/**
/*
* Fallback to the pure PHP implementation from Symfony Polyfill for PHP 7.2
*
* @see https://github.com/symfony/polyfill-php72/blob/v1.26.0/Php72.php
Expand Down
20 changes: 10 additions & 10 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
} catch (Exception $e) {
$resultBodyHtml .= '<pre>Error while checking the XML :'.$e.'</pre>';
}
if ($result === true) {
if (true === $result) {
$resultHeaderClass = 'success';
$resultBodyHtml .= '<div class="alert alert-success">XML Factur-X valid.</div>';
} else {
Expand All @@ -46,25 +46,25 @@
$facturx = new \Atgp\FacturX\Facturx();
$resultHeaderHtml = 'Generate PDF Factur-X from PDF and Factur-X XML result';
try {
if ($_POST['file_as_string'] == 'true') {
if ('true' == $_POST['file_as_string']) {
$pdf = file_get_contents($_FILES['pdf_classic']['tmp_name']);
$facturx_xml = file_get_contents($_FILES['xml_facturx_tolink']['tmp_name']);
} else {
$pdf = $_FILES['pdf_classic']['tmp_name'];
$facturx_xml = $_FILES['xml_facturx_tolink']['tmp_name'];
}
$attachment_files = array();
$attachment_files = [];
if (!empty($_FILES['attachment']['tmp_name'])) {
$attachment_files[] = array(
$attachment_files[] = [
'name' => $_FILES['attachment']['name'],
'desc' => $_POST['attachment_desc'],
'path' => $_FILES['attachment']['tmp_name'],
);
];
}
$result = $facturx->generateFacturxFromFiles($pdf, $facturx_xml,
'autodetect', true, __DIR__.'/', $attachment_files, true, $_POST['relationship']);
} catch (Exception $e) {
$resultBodyHtml = 'Error while generating the Factur-X :<pre>' . $e.'</pre>';
$resultBodyHtml = 'Error while generating the Factur-X :<pre>'.$e.'</pre>';
}
if (!empty($result)) {
$resultHeaderClass = 'success';
Expand Down Expand Up @@ -152,15 +152,15 @@
</form>
</div>
</div>
<?php if (!empty($resultBodyHtml)){ ?>
<?php if (!empty($resultBodyHtml)) { ?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header bg-<?php echo $resultHeaderClass ?> text-white">
<?php echo $resultHeaderHtml ?>
<div class="card-header bg-<?php echo $resultHeaderClass; ?> text-white">
<?php echo $resultHeaderHtml; ?>
</div>
<div class="card-body">
<?php echo $resultBodyHtml ?>
<?php echo $resultBodyHtml; ?>
</div>
</div>
</div>
Expand Down

0 comments on commit a5ccab2

Please sign in to comment.