From 2ecc7e73a5373305deeb126e21c32a5a86ed2aab Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Tue, 14 Jun 2022 14:30:31 +0200
Subject: [PATCH] dev#154000 : fix format

---
 library/Class/Article/MetaData.php      |  9 ++----
 library/Class/Notice/ZoteroMetaData.php | 41 ++++++++++++-------------
 tests/scenarios/Zotero/ZoteroTest.php   |  3 --
 3 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/library/Class/Article/MetaData.php b/library/Class/Article/MetaData.php
index 03d5614a253..f4e114590c3 100644
--- a/library/Class/Article/MetaData.php
+++ b/library/Class/Article/MetaData.php
@@ -23,8 +23,7 @@
 class Class_Article_MetaData  extends Class_MetaData_Generator {
   protected $_mapping;
 
-
-  public function injectOpenGraph($script_loader) {
+  public function injectOpenGraph(Class_ScriptLoader $script_loader) : self {
     $description = $this->_getSummary();
     $script_loader
       ->addMeta('og:type','article')
@@ -37,18 +36,17 @@ class Class_Article_MetaData  extends Class_MetaData_Generator {
   }
 
 
-  protected function _getSummary() {
+  protected function _getSummary() : string {
     return html_entity_decode(trim(strip_tags(preg_replace('/<script.*<\/script>/i',
                                                            '',
                                                            $this->_record->getSummary()))));
   }
 
 
-  public  function getMapping(){
+  public  function getMapping() : array {
     if ($this->_record->getNotice()) {
       $this->_record = $this->_record->getNotice();
       return (new Class_Notice_ZoteroMetaData())->getZoteroMapping($this->_record->getZoteroLabel());
-
     }
     return [
             'title' =>  fn($record) => $record->getTitre(),
@@ -59,7 +57,6 @@ class Class_Article_MetaData  extends Class_MetaData_Generator {
             'blogTitle' => fn($record) => Class_Profil::getCurrentProfil()->getTitreSite(),
             'publicationTitle' => 'Titre',
             'creators' => fn($record) => [$record->getAuthorName()],
-
     ];
   }
 }
diff --git a/library/Class/Notice/ZoteroMetaData.php b/library/Class/Notice/ZoteroMetaData.php
index e27b9120177..5cb3e85dd88 100644
--- a/library/Class/Notice/ZoteroMetaData.php
+++ b/library/Class/Notice/ZoteroMetaData.php
@@ -24,43 +24,42 @@ class Class_Notice_ZoteroMetaData {
   protected $_record,
     $_mapping;
 
-  public function getZoteroMapping($label_zotero){
+  public function getZoteroMapping( string $label_zotero) : array {
 
     if ($this->_mapping)
       return $this->_mapping;
 
+    $label_zotero = ( $label_zotero ? $label_zotero : 'book');
 
-    $label_zotero=( $label_zotero ? $label_zotero : 'book');
-
-    $default = ['type', 'creators', 'editors', 'producers', 'contributors', 'translators','keywords', 'attachments'];
+    $default = ['type', 'creators', 'editors', 'producers', 'contributors', 'translators', 'keywords', 'attachments'];
     if ($label_zotero) {
       $zotero_for_type = array_map( fn($codif)=>($codif['field']),
-                                  Class_CodifTypeDoc::getZoteroAttributesForType($label_zotero));
+                                   Class_CodifTypeDoc::getZoteroAttributesForType($label_zotero));
       $default = array_merge($default, $zotero_for_type);
     }
 
-    return $this->_mapping= array_filter($this->getMapping(),
+    return $this->_mapping = array_filter($this->getMapping(),
                                          fn($k) => in_array($k, $default),
                                          ARRAY_FILTER_USE_KEY);
   }
 
 
-  protected function _firstPublicationDate($dates) {
+  protected function _firstPublicationDate(array $dates) : string {
     foreach( $dates as  $date)
-      if ( $exploded = explode(',', $date))
+      if ( $exploded = explode(', ', $date))
         return preg_replace('/\D/', '', current($exploded));
     return '';
   }
 
 
-  protected function _getUrl($record) {
+  protected function _getUrl( Class_Notice $record ) : array {
     if( $album = $record->getAlbum() )
-      return $album->getExternalUri() ?? '';
-    return  $record->get_subfield('856', 'u') ?? '';
+      return ($uri =  $album->getExternalUri()) ? [ $uri ] : [];
+    return  $record->get_subfield('856', 'u') ?? [];
   }
 
 
-  protected function _getFirstUnimarcField( Class_Notice $record, array $fields ): array {
+  protected function _getFirstUnimarcField( Class_Notice $record, array $fields ) : array {
     foreach ($fields as $field) {
       $zone= explode('$', $field);
       if (count( $zone) > 1
@@ -71,7 +70,7 @@ class Class_Notice_ZoteroMetaData {
   }
 
 
-  public function getMapping(){
+  public function getMapping() : array {
     return [
             'type'  => fn($record) => ($record->getZoteroLabel() ? $record->getZoteroLabel() : 'book'),
             'title' => fn($record) => (implode(' : ', $record->getTitresDansZones(['200$a', '200$e', '200$h', '200$i']))),
@@ -80,7 +79,7 @@ class Class_Notice_ZoteroMetaData {
                                                      $record->getSerieTitle()]),
             'seriesNumber' => 'TomeAlpha',
             'edition' => 'MentionEdition',
-            'place' => fn($record) =>  $this->_getFirstUnimarcField($record, ['214$a', '711$c','712$c','210$a']),
+            'place' => fn($record) =>  $this->_getFirstUnimarcField($record, ['214$a', '711$c', '712$c', '210$a']),
             'publisher' => 'FirstEditeur',
             'numPages' => fn($record) => current(explode(';', (preg_replace('#[^()]*\((.*?)\)[^()]*#', '\1' ,$record->getCollation())))),
             'pages' => fn($record) => current(explode(';', (preg_replace('#[^()]*\((.*?)\)[^()]*#', '\1' ,$record->getCollation())))),
@@ -91,7 +90,7 @@ class Class_Notice_ZoteroMetaData {
             //            'doi'=> fn($record) => $record->get_subfield('035', 'a'),
             'language' => 'LangueCodes',
             'url' => fn($record) =>  $this->_getUrl($record),
-            'university' => fn($record) => $this->_getFirstUnimarcField( $record, ['328$e', '712$a', '711$a','210$c']) ,
+            'university' => fn($record) => $this->_getFirstUnimarcField( $record, ['328$e', '712$a', '711$a', '210$c']) ,
             'shortTitle' => fn($record) => $record->get_subfield('200', 'a'),
             'volume' => fn($record) => $record->getVolume() ?? $record->getTomeAlpha(),
             'numberOfVolumes' => fn($record) => preg_replace('/\D/', '', current(explode('(', current($record->getCollations())))),
@@ -102,17 +101,17 @@ class Class_Notice_ZoteroMetaData {
             'libraryCatalog' => fn($record) => $record->getAbsoluteUrl(),
             'creators'  => function($record) {
               $creators = $record->getAllAuthorsFromZones(['700']);
-              $others = ( $record->getZoteroLabel() == 'thesis') ? [] : $record->getAllAuthorsFromZonesAndResponsibility(['701'], ['300', '370','727']);
-              if (array_merge($creators,$others))
-                  return array_merge($creators,$others);
+              $others = ( $record->getZoteroLabel() == 'thesis') ? [] : $record->getAllAuthorsFromZonesAndResponsibility(['701'], ['300', '370', '727']);
+              if (array_merge($creators, $others))
+                return array_merge($creators, $others);
 
-            if (! $article = $record->getArticle())
+              if (! $article = $record->getArticle())
                 return [];
               return [$article->getAuthorName()];},
             'editors'   => fn($record) => $record->getAllAuthorsFromZonesAndResponsibility(['702'], ['340']),
             'producers'   => fn($record) => $record->getAllAuthorsFromZonesAndResponsibility(['702'], ['630']),
-            'contributors'  => fn($record) =>  ($record->getZoteroLabel() == 'thesis' ) ? $record->getAllAuthorsFromZones(['701','702', '711']) : $record->getAllAuthorsFromZonesAndResponsibility(['702'], ['100', '205']),
-            'translators'  => fn($record) => $record->getAllAuthorsFromZonesAndResponsibility(['701','702'], ['730']),
+            'contributors'  => fn($record) =>  ($record->getZoteroLabel() == 'thesis' ) ? $record->getAllAuthorsFromZones(['701', '702', '711']) : $record->getAllAuthorsFromZonesAndResponsibility(['702'], ['100', '205']),
+            'translators'  => fn($record) => $record->getAllAuthorsFromZonesAndResponsibility(['701', '702'], ['730']),
             'keywords' => fn($record) => $record->getMatieresLabels(),
             'attachments' => fn($record) => $record->get_subfield('003')
 
diff --git a/tests/scenarios/Zotero/ZoteroTest.php b/tests/scenarios/Zotero/ZoteroTest.php
index 5f7b0ba2fa2..fe575ceeadb 100644
--- a/tests/scenarios/Zotero/ZoteroTest.php
+++ b/tests/scenarios/Zotero/ZoteroTest.php
@@ -58,7 +58,6 @@ abstract class ZoteroTestCase extends AbstractControllerTestCase {
                    ['id' => '702',
                     'libelle' => 'Directeur de these']);
 
-
     $this->_buildTemplateProfil(['id' => 1,
                                  'libelle' => 'Hérisson']);
   }
@@ -419,7 +418,6 @@ class ZoteroSerialTest extends ZoteroTestCase {
             ['og:type', 'article'],
             ['Z.itemType', 'journalArticle'],
             ['dc.identifier', '979-10-360-0022-5'],
-            //            ['Z.pages', '95 p.'],
             ['Z.series', 'Les petits cahiers'],
             ['Z.issue', 3]
     ];
@@ -561,7 +559,6 @@ class ZoteroArteVideoRisTest extends ZoteroTestCase {
                              'external_uri' => 'https://music.1dtouch.com/albums/999',
                             ])->assertSave();
 
-
     Class_TypeDoc::find(Class_TypeDoc::DVD)->setLabelZotero('film')->save();
     $this->uniqueDispatch('/zotero/export?id=3&format=ris');
   }
-- 
GitLab