Skip to content

Commit

Permalink
remove deprecated currentParams from Translator
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Oct 12, 2024
1 parent 14ab64b commit 686b28f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 44 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Check outdated packages
run: composer outdated

- name: Run tests
run: vendor/bin/phpunit

- name: Run static code analysis
run: vendor/bin/phpstan --xdebug analyse
if: always()


3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"autoload": {
"psr-4": {
"leandrogehlen\\querybuilder\\": "src"
"leandrogehlen\\querybuilder\\": "src",
"leandrogehlen\\querybuilder\\tests\\": "tests"
}
},
"extra": {
Expand Down
24 changes: 3 additions & 21 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* $rules = Yii::$app->request->post('rules');
*
* if ($rules) {
* $translator = new Translator(Json::decode($rules),['currentParams'=>$query->params]);
* $translator = new Translator(Json::decode($rules));
* $query->andWhere($translator->where())
* ->addParams($translator->params());
* }
Expand All @@ -44,11 +44,7 @@ class Translator extends BaseObject
/** @var array<string, mixed> */
private array $_operators;

/**
* @var array<string, mixed> The params from yii\db\Query object that are already set so we don't overwrite them
* @deprecated
*/
private array $currentParams = [];


/**
* Constructors.
Expand All @@ -57,10 +53,6 @@ class Translator extends BaseObject
*/
public function __construct($data, $config = [])
{
if(isset($config['currentParams'])){
$this->setCurrentParams($config['currentParams']);

}
parent::__construct($config);
$this->_where = $this->buildWhere($data);
}
Expand Down Expand Up @@ -180,7 +172,7 @@ public function where()
*/
public function params()
{
return array_merge($this->currentParams, $this->_params);
return $this->_params;
}

/**
Expand All @@ -193,14 +185,4 @@ private function getNewParamName(){
return $security->generateRandomString(20);
}

/**
*
* @param array<string, mixed> $currentParams
* @deprecated
*/
public function setCurrentParams($currentParams) : void {
$this->currentParams = $currentParams;
}


}
19 changes: 1 addition & 18 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace leandrogehlen\querybuilder\tests\unit;
namespace leandrogehlen\querybuilder\tests;

use yii\base\NotSupportedException;
use Yii;
Expand All @@ -10,23 +10,6 @@
*/
class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* This method is called before the first test of this test class is run.
* Attempts to load vendor autoloader.
* @throws \yii\base\NotSupportedException
*/
public static function setUpBeforeClass() : void
{
$vendorDir = __DIR__ . '/../vendor';
$vendorAutoload = $vendorDir . '/autoload.php';
if (file_exists($vendorAutoload)) {
require_once($vendorAutoload);
} else {
throw new NotSupportedException("Vendor autoload file '{$vendorAutoload}' is missing.");
}
require_once($vendorDir . '/yiisoft/yii2/Yii.php');
Yii::setAlias('@vendor', $vendorDir);
}

/**
* Populates Yii::$app with a new application
Expand Down
6 changes: 4 additions & 2 deletions tests/TranslatorTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php


namespace leandrogehlen\querybuilder\tests\unit;
namespace leandrogehlen\querybuilder\tests;

use leandrogehlen\querybuilder\Translator;
use PascalDeVink\ShortUuid\ShortUuid;

class TranslatorTest extends TestCase
{
Expand Down Expand Up @@ -124,6 +123,9 @@ public function testRules($rule, $expected)
public function testHasParamValues($rule, $expected) {
$translator = new Translator($rule);
$params = $translator->params();
if(empty($expected[1])) {
$this->assertEquals([], $params);
}
foreach ($expected[1] as $key => $value) {
$values = array_values($params);
$this->assertTrue(in_array($value,$values));
Expand Down

0 comments on commit 686b28f

Please sign in to comment.