| Conditions | 13 |
| Paths | 418 |
| Total Lines | 99 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 16 | function b_bookshop_recomm_show($options) |
||
| 17 | { |
||
| 18 | // '10|0'; // See 10 books, for all categories or a particular category |
||
| 19 | global $xoopsConfig, $xoopsTpl; |
||
| 20 | include XOOPS_ROOT_PATH . '/modules/bookshop/include/common.php'; |
||
| 21 | $tblLivres = $tblCategories = $tblTmp = $tbl_tmp_vat = $tbl_vat = $tbl_tmp_lang = $block = $tbl_books_id = array(); |
||
| 22 | $tblLivres = $h_bookshop_books->getRecentRecommendedBooks(0, $options[0], $options[1]); |
||
| 23 | if ($h_bookshop_books->getRecommendedCount() > $options[0]) { // Il y a plus de livres recommand�s dans la BDD que dans le bloc, on affiche donc un lien vers la page des livres recommand�s |
||
| 24 | $block['showMore'] = true; |
||
| 25 | } |
||
| 26 | |||
| 27 | if (count($tblLivres) > 0) { |
||
| 28 | $url = BOOKSHOP_URL . 'assets/css/bookshop.css'; |
||
| 29 | $block['nostock_msg'] = bookshop_getmoduleoption('nostock_msg'); |
||
| 30 | $xoopsTpl->assign('xoops_module_header', "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\" />"); |
||
| 31 | $tblTmp = array(); |
||
| 32 | foreach ($tblLivres as $item) { |
||
| 33 | $tblTmp[] = $item->getVar('book_cid'); |
||
| 34 | $tbl_tmp_vat[] = $item->getVar('book_vat_id'); |
||
| 35 | $tbl_tmp_lang[] = $item->getVar('book_lang_id'); |
||
| 36 | $tbl_books_id[] = $item->getVar('book_id'); |
||
| 37 | } |
||
| 38 | $tblTmp = array_unique($tblTmp); |
||
| 39 | $tbl_tmp_vat = array_unique($tbl_tmp_vat); |
||
| 40 | $tbl_tmp_lang = array_unique($tbl_tmp_lang); |
||
| 41 | |||
| 42 | sort($tbl_tmp_lang); |
||
| 43 | sort($tblTmp); |
||
| 44 | sort($tbl_tmp_vat); |
||
| 45 | sort($tbl_books_id); |
||
| 46 | |||
| 47 | // Get languages ******************************************* |
||
| 48 | if (count($tbl_tmp_lang) > 0) { |
||
| 49 | $tbl_lang = $h_bookshop_lang->getObjects(new Criteria('lang_id', '(' . implode(',', $tbl_tmp_lang) . ')', 'IN'), true); |
||
| 50 | } |
||
| 51 | |||
| 52 | // Get the list of categories **************************** |
||
| 53 | $tblCategories = $h_bookshop_cat->getObjects(new Criteria('cat_cid', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
||
| 54 | |||
| 55 | // Get VAT *********************************************** |
||
| 56 | if (count($tbl_tmp_vat) > 0) { |
||
| 57 | $tbl_vat = $h_bookshop_vat->getObjects(new Criteria('vat_id', '(' . implode(',', $tbl_tmp_vat) . ')', 'IN'), true); |
||
| 58 | } |
||
| 59 | |||
| 60 | // Get the authors, deuxi�me partie ************************** |
||
| 61 | $tbl_books_auteurs = array(); |
||
| 62 | $tbl_auteurs = $h_bookshop_booksauthors->getObjects(new Criteria('ba_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
||
| 63 | if (count($tbl_auteurs) > 0) { |
||
| 64 | foreach ($tbl_auteurs as $item) { |
||
| 65 | $tbl_tmp_auteurs[] = $item->getVar('ba_auth_id'); |
||
| 66 | // Grouping data by book |
||
| 67 | $tbl_books_auteurs[$item->getVar('ba_book_id')][] = $item; |
||
| 68 | } |
||
| 69 | $tbl_tmp_auteurs = array_unique($tbl_tmp_auteurs); |
||
| 70 | sort($tbl_tmp_auteurs); |
||
| 71 | // Then recovered the information from these authors / translators |
||
| 72 | $tbl_infos_auteurs = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tbl_tmp_auteurs) . ')', 'IN'), true); |
||
| 73 | } |
||
| 74 | foreach ($tblLivres as $item) { |
||
| 75 | $tbl_tmp = array(); |
||
| 76 | $tbl_tmp = $item->toArray(); |
||
| 77 | $tbl_tmp['book_category'] = $tblCategories[$item->getVar('book_cid')]; |
||
| 78 | $tbl_tmp['book_language'] = $tbl_lang[$item->getVar('book_lang_id')]; |
||
| 79 | $tbl_tmp['book_vat_rate'] = $tbl_vat[$item->getVar('book_vat_id')]; |
||
| 80 | $tbl_tmp['book_price_ttc'] = bookshop_getTTC($item->getVar('book_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
| 81 | $tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($item->getVar('book_discount_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
| 82 | |||
| 83 | // Search for authors / translators |
||
| 84 | $tbl_join1 = $tbl_join2 = array(); |
||
| 85 | $tbl_tmp2 = $tbl_books_auteurs[$item->getVar('book_id')]; // Returns a list of all authors / translators of a book |
||
| 86 | $tbl_livre_auteurs = $tbl_livre_traducteurs = array(); |
||
| 87 | foreach ($tbl_tmp2 as $oneauthor) { |
||
| 88 | $auteur = $tbl_infos_auteurs[$oneauthor->getVar('ba_auth_id')]; |
||
| 89 | if ($oneauthor->getVar('ba_type') == 1) { |
||
| 90 | $tbl_livre_auteurs[] = $auteur->toArray(); |
||
| 91 | $tbl_join1[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
| 92 | } else { |
||
| 93 | $tbl_livre_traducteurs[] = $auteur->toArray(); |
||
| 94 | $tbl_join2[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | if (count($tbl_join1) > 0) { |
||
| 98 | $tbl_tmp['book_joined_authors'] = implode(', ', $tbl_join1); |
||
| 99 | } |
||
| 100 | if (count($tbl_join2) > 0) { |
||
| 101 | $tbl_tmp['book_joined_translators'] = implode(',', $tbl_join2); |
||
| 102 | } |
||
| 103 | $tbl_tmp['book_authors'] = $tbl_livre_auteurs; |
||
| 104 | $tbl_tmp['book_translators'] = $tbl_livre_traducteurs; |
||
| 105 | // Et on place le tout dans le template |
||
| 106 | $block['block_books'][] = $tbl_tmp; |
||
| 107 | } |
||
| 108 | |||
| 109 | return $block; |
||
| 110 | } else { // The list of books is not found (it is not books sold in the stock books) |
||
| 111 | |||
| 112 | return false; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 159 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.