Simplify a little some array queries
This commit is contained in:
		
							parent
							
								
									a6b52887ff
								
							
						
					
					
						commit
						24e0a14b89
					
				
					 2 changed files with 9 additions and 15 deletions
				
			
		
							
								
								
									
										22
									
								
								book.php
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								book.php
									
										
									
									
									
								
							|  | @ -235,12 +235,10 @@ class Book extends Base { | ||||||
| 
 | 
 | ||||||
|     public function getDataById ($idData) |     public function getDataById ($idData) | ||||||
|     { |     { | ||||||
|         foreach ($this->getDatas () as $data) { |         $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) { | ||||||
|             if ($data->id == $idData) { |             return $data->id == $idData; | ||||||
|                 return $data; |         }); | ||||||
|             } |         return reset ($reduced); | ||||||
|         } |  | ||||||
|         return NULL; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getRating () { |     public function getRating () { | ||||||
|  | @ -283,14 +281,10 @@ class Book extends Base { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getDataFormat ($format) { |     public function getDataFormat ($format) { | ||||||
|         foreach ($this->getDatas () as $data) |         $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { | ||||||
|         { |             return $data->format == $format; | ||||||
|             if ($data->format == $format) |         }); | ||||||
|             { |         return reset ($reduced); | ||||||
|                 return $data; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return NULL; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getFilePath ($extension, $idData = NULL, $relative = false) |     public function getFilePath ($extension, $idData = NULL, $relative = false) | ||||||
|  |  | ||||||
|  | @ -290,7 +290,7 @@ class BookTest extends PHPUnit_Framework_TestCase | ||||||
|         $data = $book->getDataFormat ("PDF"); |         $data = $book->getDataFormat ("PDF"); | ||||||
|         $this->assertEquals (19, $data->id); |         $this->assertEquals (19, $data->id); | ||||||
| 
 | 
 | ||||||
|         $this->assertNull ($book->getDataFormat ("FB2")); |         $this->assertFalse ($book->getDataFormat ("FB2")); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public function testGetMimeType  () { |     public function testGetMimeType  () { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue