@@ -1515,18 +1515,13 @@ public function createStream(string $content = ''): StreamInterface
15151515
15161516 public function createStreamFromFile (string $ filename , string $ mode = 'r ' ): StreamInterface
15171517 {
1518- try {
1519- $ resource = @\fopen ($ filename , $ mode );
1520- } catch (\Throwable $ e ) {
1521- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ filename ));
1522- }
1523-
1518+ $ resource = @\fopen ($ filename , $ mode );
15241519 if (false === $ resource ) {
1525- if ('' === $ mode || false === \in_array ($ mode [0 ], ['r ' , 'w ' , 'a ' , 'x ' , 'c ' ], true )) {
1526- throw new \InvalidArgumentException (\sprintf ( 'The mode "%s" is invalid. ' , $ mode ) );
1520+ if ('' === $ mode || false === \in_array ($ mode [0 ], ['r ' , 'w ' , 'a ' , 'x ' , 'c ' ])) {
1521+ throw new \InvalidArgumentException ('The mode ' . $ mode . ' is invalid. ' );
15271522 }
15281523
1529- throw new \RuntimeException (\sprintf ( 'The file "%s" cannot be opened. ' , $ filename ) );
1524+ throw new \RuntimeException ('The file ' . $ filename . ' cannot be opened. ' );
15301525 }
15311526
15321527 return Stream::create ($ resource );
@@ -2382,7 +2377,7 @@ public function seek($offset, $whence = \SEEK_SET) /*:void*/
23822377 }
23832378
23842379 if (-1 === \fseek ($ this ->stream , $ offset , $ whence )) {
2385- throw new \RuntimeException ('Unable to seek to stream position " ' . $ offset . '" with whence ' . \var_export ($ whence , true ));
2380+ throw new \RuntimeException ('Unable to seek to stream position ' . $ offset . ' with whence ' . \var_export ($ whence , true ));
23862381 }
23872382 }
23882383
@@ -2573,11 +2568,9 @@ public function getStream(): StreamInterface
25732568 return $ this ->stream ;
25742569 }
25752570
2576- try {
2577- return Stream::create (\fopen ($ this ->file , 'r ' ));
2578- } catch (\Throwable $ e ) {
2579- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ this ->file ));
2580- }
2571+ $ resource = \fopen ($ this ->file , 'r ' );
2572+
2573+ return Stream::create ($ resource );
25812574 }
25822575
25832576 public function moveTo ($ targetPath ) /*:void*/
@@ -2596,13 +2589,8 @@ public function moveTo($targetPath) /*:void*/
25962589 $ stream ->rewind ();
25972590 }
25982591
2599- try {
2600- // Copy the contents of a stream into another stream until end-of-file.
2601- $ dest = Stream::create (\fopen ($ targetPath , 'w ' ));
2602- } catch (\Throwable $ e ) {
2603- throw new \RuntimeException (\sprintf ('The file "%s" cannot be opened. ' , $ targetPath ));
2604- }
2605-
2592+ // Copy the contents of a stream into another stream until end-of-file.
2593+ $ dest = Stream::create (\fopen ($ targetPath , 'w ' ));
26062594 while (!$ stream ->eof ()) {
26072595 if (!$ dest ->write ($ stream ->read (1048576 ))) {
26082596 break ;
@@ -2613,7 +2601,7 @@ public function moveTo($targetPath) /*:void*/
26132601 }
26142602
26152603 if (false === $ this ->moved ) {
2616- throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to "%s" ' , $ targetPath ));
2604+ throw new \RuntimeException (\sprintf ('Uploaded file could not be moved to %s ' , $ targetPath ));
26172605 }
26182606 }
26192607
@@ -2688,7 +2676,7 @@ public function __construct(string $uri = '')
26882676 {
26892677 if ('' !== $ uri ) {
26902678 if (false === $ parts = \parse_url ($ uri )) {
2691- throw new \InvalidArgumentException (\sprintf ( ' Unable to parse URI: "%s" ' , $ uri) );
2679+ throw new \InvalidArgumentException (" Unable to parse URI: $ uri" );
26922680 }
26932681
26942682 // Apply parse_url parts to a URI.
@@ -6522,7 +6510,7 @@ public function __construct(string $dsn, /*?string*/ $user = null, /*?string*/ $
65226510 // explicitly NOT calling super::__construct
65236511 }
65246512
6525- public function addInitCommand (string $ command )/*: void*/
6513+ public function addInitCommand (string $ command ) /*: void*/
65266514 {
65276515 $ this ->commands [] = $ command ;
65286516 }
@@ -6607,17 +6595,17 @@ public function prepare($statement, $options = array())
66076595 return $ this ->pdo ()->prepare ($ statement , $ options );
66086596 }
66096597
6610- public function quote ($ string , $ parameter_type = null ): string
6598+ public function quote ($ string , $ parameter_type = \ PDO :: PARAM_STR ): string
66116599 {
66126600 return $ this ->pdo ()->quote ($ string , $ parameter_type );
66136601 }
66146602
6615- public function lastInsertId (/* ?string */ $ name = null ): string
6603+ public function lastInsertId ( /* ?string */ $ name = null ): string
66166604 {
66176605 return $ this ->pdo ()->lastInsertId ($ name );
66186606 }
66196607
6620- public function query ($ query , /* ?int */ $ fetchMode = null , ...$ fetchModeArgs ): \PDOStatement
6608+ public function query ($ query , /* ?int */ $ fetchMode = null , ...$ fetchModeArgs ): \PDOStatement
66216609 {
66226610 return call_user_func_array (array ($ this ->pdo (), 'query ' ), func_get_args ());
66236611 }
@@ -9106,7 +9094,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
91069094 use Tqdev \PhpCrudApi \Controller \Responder ;
91079095 use Tqdev \PhpCrudApi \Middleware \Base \Middleware ;
91089096 use Tqdev \PhpCrudApi \Middleware \Router \Router ;
9109- use Tqdev \PhpCrudApi \RequestUtils ;
91109097 use Tqdev \PhpCrudApi \ResponseFactory ;
91119098
91129099 class XmlMiddleware extends Middleware
@@ -9163,7 +9150,7 @@ private function json2xml($json, $types = 'null,boolean,number,string,object,arr
91639150 if ($ t ($ v ) == 'boolean ' ) {
91649151 $ va ->appendChild ($ d ->createTextNode ($ v ? 'true ' : 'false ' ));
91659152 } else {
9166- $ va ->appendChild ($ d ->createTextNode ($ v ));
9153+ $ va ->appendChild ($ d ->createTextNode (( string ) $ v ));
91679154 }
91689155 $ ch = $ c ->appendChild ($ va );
91699156 if (in_array ($ t ($ v ), $ ts )) {
@@ -9178,15 +9165,15 @@ private function json2xml($json, $types = 'null,boolean,number,string,object,arr
91789165 return $ d ->saveXML ($ d ->documentElement );
91799166 }
91809167
9181- private function xml2json ($ xml )
9168+ private function xml2json ($ xml ): string
91829169 {
91839170 $ o = @simplexml_load_string ($ xml );
9184- if ($ o ===false ) {
9185- return null ;
9171+ if ($ o === false ) {
9172+ return '' ;
91869173 }
91879174 $ a = @dom_import_simplexml ($ o );
91889175 if (!$ a ) {
9189- return null ;
9176+ return '' ;
91909177 }
91919178 $ t = function ($ v ) {
91929179 $ t = $ v ->getAttribute ('type ' );
@@ -9224,7 +9211,7 @@ private function xml2json($xml)
92249211 return $ c ;
92259212 };
92269213 $ c = $ f ($ f , $ a );
9227- return json_encode ($ c );
9214+ return ( string ) json_encode ($ c );
92289215 }
92299216
92309217 public function process (ServerRequestInterface $ request , RequestHandlerInterface $ next ): ResponseInterface
0 commit comments