Skip to content

Commit

Permalink
Merge pull request #96 from KumbiaPHP/dev
Browse files Browse the repository at this point in the history
Merge dev branch in master
  • Loading branch information
joanhey authored Apr 3, 2020
2 parents 0a0cac2 + 5c38c32 commit 20d758e
Show file tree
Hide file tree
Showing 30 changed files with 789 additions and 531 deletions.
35 changes: 14 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
language: php
dist: trusty
dist: bionic

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- master
- 7.4
- nightly

matrix:
allow_failures:
- php: master
- php: 5.5
- php: nightly

notifications:
slack: kumbiaphp:51JaKQTXASwf52D8b32OyWb9
# irc: "irc.freenode.org#kumbiaphp"
# email:
# - programador.manuel@gmail.com
# - xxxxx@gmail.com


env:
- DB=mysql
# - DB=pgsql
# - DB=sqlite
services:
- mysql
- postgresql

before_script:
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database test;' -U postgres; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS test;'; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE TABLE IF NOT EXISTS test.usuario ( id int(11) NOT NULL DEFAULT 0, nombre varchar(50) NOT NULL , email varchar(100) NOT NULL , activo tinyint(1) NULL DEFAULT 1 , PRIMARY KEY (id) );'; fi"

- "mysql -e 'DROP DATABASE IF EXISTS kumbia_test;'"
- "mysql -e 'create database kumbia_test;'"
- "psql -c 'DROP DATABASE IF EXISTS kumbia_test;' -U postgres"
- "psql -c 'create database kumbia_test;' -U postgres"
script:
- phpunit --configuration tests/phpunit_$DB.xml --coverage-text --colors --coverage-clover=coverage.clover
- phpunit --configuration tests/phpunit.xml --coverage-text --colors --coverage-clover=coverage.clover
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
21 changes: 8 additions & 13 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @category Kumbia
*
* @copyright 2005 - 2016 Kumbia Team (http://www.kumbiaphp.com)
* @copyright 2005 - 2020 Kumbia Team (http://www.kumbiaphp.com)
* @license http://wiki.kumbiaphp.com/Licencia New BSD License
*/

Expand Down Expand Up @@ -118,7 +118,7 @@ public function populate($rel)
*/
public static function pagination($params = [], $values = [], $page = 1, $per_page = 10)
{
$model = get_called_class();
$model = static::class;
unset($params['limit'], $params['offset']);
$sql = QueryGenerator::select($model::getSource(), $model::getDriver(), $params);

Expand All @@ -134,12 +134,9 @@ public static function pagination($params = [], $values = [], $page = 1, $per_pa
*
* @return int numero de registros actualizados
*/
public static function updateAll(array $fields, $where = null, array $values = [])
public static function updateAll(array $fields, string $where = '', array $values = [])
{
if ($values !== null && !is_array($values)) {
$values = \array_slice(\func_get_args(), 2);
}
$sql = QueryGenerator::updateAll(\get_called_class(), $fields, $values, $where);
$sql = QueryGenerator::updateAll(static::class, $fields, $values, $where);
$sth = self::prepare($sql);
$sth->execute($values);

Expand Down Expand Up @@ -331,13 +328,11 @@ public static function allBy($field, $value, $params = [])
*
* @return int
*/
public static function count($where = null, $values = null)
public static function count(string $where = '', array $values = [])
{
$source = static::getSource();
$sql = QueryGenerator::count($source, $where);
if ($values !== null && !is_array($values)) {
$values = \array_slice(\func_get_args(), 1);
}

$sth = static::query($sql, $values);

return $sth->fetch()->count;
Expand All @@ -353,7 +348,7 @@ public static function count($where = null, $values = null)
*
* @return Paginator
*/
public static function paginate(array $params, $page, $perPage, $values = null)
public static function paginate(array $params, int $page, int $perPage, $values = null)
{
unset($params['limit'], $params['offset']);
$sql = QueryGenerator::select(static::getSource(), static::getDriver(), $params);
Expand All @@ -363,7 +358,7 @@ public static function paginate(array $params, $page, $perPage, $values = null)
$values = \array_slice(func_get_args(), 3);
}

return new Paginator(\get_called_class(), $sql, (int) $page, (int) $perPage, $values);
return new Paginator(static::class, $sql, $page, $perPage, $values);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @category Kumbia
*
* @copyright 2005 - 2016 Kumbia Team (http://www.kumbiaphp.com)
* @copyright 2005 - 2020 Kumbia Team (http://www.kumbiaphp.com)
* @license http://wiki.kumbiaphp.com/Licencia New BSD License
*/
namespace Kumbia\ActiveRecord;
Expand Down Expand Up @@ -42,8 +42,8 @@ public static function autoload($className)
if (0 !== \strpos($className, 'Kumbia\\ActiveRecord')) {
return;
}
$className = \substr($className, 19);
$fileName = \str_replace(['_', '\\'], \DIRECTORY_SEPARATOR, $className).'.php';

$fileName = \str_replace('\\', \DIRECTORY_SEPARATOR, \substr($className, 19)).'.php';
require __DIR__.$fileName;
}
}
Loading

0 comments on commit 20d758e

Please sign in to comment.