Skip to content

Commit

Permalink
feat: Moved entities to src/Entity directory + minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmolinacano committed Oct 9, 2024
1 parent 5812b9f commit d012d0e
Show file tree
Hide file tree
Showing 36 changed files with 100 additions and 75 deletions.
7 changes: 7 additions & 0 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

class Autoloader
{
// Exceptions based on: https://devdocs.prestashop-project.org/8/modules/creation/module-file-structure/
const EXCEPTIONS_FOR_UNCAPITALIZE = ['Entity', 'Controller'];

/**
* Registers the autoloader according to PrestaShop standards, which are PSR-12 standards.
* More info at: https://www.php-fig.org/psr/psr-12/
Expand Down Expand Up @@ -74,6 +77,10 @@ private static function pathFromNamespace($fullNameSpace)
*/
private static function uncapitalize($text)
{
if (in_array($text, self::EXCEPTIONS_FOR_UNCAPITALIZE, true)) {
return $text;
}

return strtolower(substr($text, 0, 1)) . substr($text, 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Lib\DoofinderConfig;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConfig;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;

$root_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$config_file_path = $root_path . '/config/config.inc.php';
Expand Down
4 changes: 2 additions & 2 deletions controllers/front/landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderApiLanding;
use PrestaShop\Module\Doofinder\Lib\SearchEngine;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderApiLanding;
use PrestaShop\Module\Doofinder\Src\Entity\SearchEngine;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
Expand Down
4 changes: 2 additions & 2 deletions doofinder-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderApi;
use PrestaShop\Module\Doofinder\Lib\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderApi;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderInstallation;

$rootPath = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$configFilePath = $rootPath . '/config/config.inc.php';
Expand Down
10 changes: 5 additions & 5 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

require_once 'autoloader.php';

use PrestaShop\Module\Doofinder\Lib\DoofinderAdminPanelView;
use PrestaShop\Module\Doofinder\Lib\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Lib\DoofinderScript;
use PrestaShop\Module\Doofinder\Lib\HookManager;
use PrestaShop\Module\Doofinder\Lib\SearchEngine;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderAdminPanelView;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderInstallation;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderScript;
use PrestaShop\Module\Doofinder\Src\Entity\HookManager;
use PrestaShop\Module\Doofinder\Src\Entity\SearchEngine;

class Doofinder extends Module
{
Expand Down
4 changes: 2 additions & 2 deletions feeds/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfCategoryBuild;
use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DfCategoryBuild;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;

if (function_exists('set_time_limit')) {
@set_time_limit(3600 * 2);
Expand Down
4 changes: 2 additions & 2 deletions feeds/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfCmsBuild;
use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DfCmsBuild;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;

if (function_exists('set_time_limit')) {
@set_time_limit(3600 * 2);
Expand Down
4 changes: 2 additions & 2 deletions feeds/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DfTools;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
6 changes: 3 additions & 3 deletions landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @license GPLv3
*/

use PrestaShop\Module\Doofinder\Lib\DoofinderConfig;
use PrestaShop\Module\Doofinder\Lib\DoofinderConstants;
use PrestaShop\Module\Doofinder\Lib\LanguageManager;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConfig;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;
use PrestaShop\Module\Doofinder\Src\Entity\LanguageManager;

$rootPath = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
$configFilePath = $rootPath . '/config/config.inc.php';
Expand Down
4 changes: 2 additions & 2 deletions lib/DfCategoryBuild.php → src/Entity/DfCategoryBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -71,7 +71,7 @@ private function buildCategory($idCategory)
$c['meta_description'] = DfTools::cleanString($category->meta_description);
$c['tags'] = DfTools::cleanString($category->meta_keywords);
$c['link'] = $this->link->getCategoryLink($category);
$c['image_link'] = $category->id_image ? $this->link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default') : '';
$c['image_link'] = $category->id_image ? $this->link->getCatImageLink($category->link_rewrite, $category->id_image, \ImageType::getFormattedName('category')) : '';

return $c;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DfCmsBuild.php → src/Entity/DfCmsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/DfProductBuild.php → src/Entity/DfProductBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
36 changes: 18 additions & 18 deletions lib/DfTools.php → src/Entity/DfTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -61,10 +61,10 @@ public static function prepareSQL($sql, $args = [])
public static function limitSQL($sql, $limit = false, $offset = false)
{
if (false !== $limit && is_numeric($limit)) {
$sql .= ' LIMIT ' . intval($limit);
$sql .= ' LIMIT ' . (int) $limit;

if (false !== $offset && is_numeric($offset)) {
$sql .= ' OFFSET ' . intval($offset);
$sql .= ' OFFSET ' . (int) $offset;
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public static function getAvailableImageSizes()
`products` = 1
ORDER BY
CASE
WHEN name = 'home_default' THEN '1'
WHEN name = '" . \ImageType::getFormattedName('home') . "' THEN '1'
END DESC;
";

Expand Down Expand Up @@ -145,9 +145,9 @@ public static function versionGte($minVersion)
$minVersion = explode('.', $minVersion);

foreach ($version as $index => $value) {
if (intval($value) > intval($minVersion[$index])) {
if ((int) $value > (int) $minVersion[$index]) {
return true;
} elseif (intval($value) < intval($minVersion[$index])) {
} elseif ((int) $value < (int) $minVersion[$index]) {
return false;
}
}
Expand Down Expand Up @@ -868,13 +868,13 @@ public static function getCategoriesForProductIdAndLanguage($idProduct, $idLang,

foreach (\Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql) as $i => $row) {
if (!$i) {
$idCategory0 = intval($row['id_category']);
$nleft0 = intval($row['nleft']);
$nright0 = intval($row['nright']);
$idCategory0 = (int) $row['id_category'];
$nleft0 = (int) $row['nleft'];
$nright0 = (int) $row['nright'];
} else {
$idCategory1 = intval($row['id_category']);
$nleft1 = intval($row['nleft']);
$nright1 = intval($row['nright']);
$idCategory1 = (int) $row['id_category'];
$nleft1 = (int) $row['nleft'];
$nright1 = (int) $row['nright'];

if ($nleft1 < $nleft0 && $nright1 > $nright0) {
// $idCategory1 is an ancestor of $idCategory0
Expand Down Expand Up @@ -981,7 +981,7 @@ public static function getCmsPages($idLang, $idShop, $active = true)

public static function truncateText($text, $length)
{
$l = intval($length);
$l = (int) $length;
$c = trim(preg_replace('/\s+/', ' ', $text));

if (strlen($c) <= $l) {
Expand Down Expand Up @@ -1169,7 +1169,7 @@ public static function getCurrencyForLanguageFromRequest(\Language $lang)
{
if ($idCurrency = \Tools::getValue('currency')) {
if (is_numeric($idCurrency)) {
$idCurrency = intval($idCurrency);
$idCurrency = (int) $idCurrency;
} else {
$idCurrency = \Currency::getIdByIsoCode(strtoupper($idCurrency));
}
Expand Down Expand Up @@ -1411,17 +1411,17 @@ public static function getOnsalePrice($productId, $includeTaxes, $variantId = nu

private static function getVariantUrl($product, $context)
{
global $lang, $shop;
$cfgModRewrite = self::cfg($shop->id, 'PS_REWRITING_SETTINGS', DoofinderConstants::YES);
$context = \Context::getContext();
$cfgModRewrite = self::cfg($context->shop->id, 'PS_REWRITING_SETTINGS', DoofinderConstants::YES);

return self::cleanURL(
$context->link->getProductLink(
(int) $product['id_product'],
$product['link_rewrite'],
$product['cat_link_rew'],
$product['ean13'],
$lang->id,
$shop->id,
$context->language->id,
$context->shop->id,
(int) $product['id_product_attribute'],
$cfgModRewrite,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
13 changes: 4 additions & 9 deletions lib/DoofinderApi.php → src/Entity/DoofinderApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Gilles Devaux (<[email protected]>) (https://github.com/flaptor/indextank-php)
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -372,15 +372,10 @@ public function removeTerm($filterName, $term)
if ($this->optionExists('filter') && isset($this->searchOptions['filter'][$filterName])
&& in_array($term, $this->searchOptions['filter'][$filterName])
) {
function filter_me($value)
{
global $term;

return $value != $term;
}

$this->searchOptions['filter'][$filterName] =
array_filter($this->searchOptions['filter'][$filterName], 'filter_me');
array_filter($this->searchOptions['filter'][$filterName], function ($value) use ($term) {
return $value !== $term;
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/DoofinderConfig.php → src/Entity/DoofinderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* - getResults: get an array with the results
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/DoofinderScript.php → src/Entity/DoofinderScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/

namespace PrestaShop\Module\Doofinder\Lib;
namespace PrestaShop\Module\Doofinder\Src\Entity;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down
Loading

0 comments on commit d012d0e

Please sign in to comment.