Skip to content

Commit

Permalink
Added is_array checks in some places.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabordemooij committed Oct 21, 2012
1 parent 84a01e2 commit 78e16a3
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ php:
before_script:
- echo 'yes' | sudo add-apt-repository ppa:cubrid/cubrid
- sudo apt-get update
- sudo apt-get install cubrid
- sudo apt-get install cubrid-8.4.0
- /etc/profile.d/cubrid.sh
- sudo apt-get install cubrid-demodb
- sudo apt-get install php5-cubrid
Expand Down
2 changes: 1 addition & 1 deletion RedBean/Adapter/DBAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getAssoc( $sql, $aValues = array() ) {
$assoc = array();
if ($rows) {
foreach($rows as $row) {
if (count($row)>0) {
if (is_array($row) && count($row)>0) {
if (count($row)>1) {
$key = array_shift($row);
$value = array_shift($row);
Expand Down
2 changes: 1 addition & 1 deletion RedBean/DuplicationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function duplicate($bean,$trail=array(),$pid=false) {
$copy->id = 0;
$tables = $this->tables;
foreach($tables as $table) {
if (count($this->filters) && !in_array($table,$this->filters)) continue;
if (is_array($this->filters) && count($this->filters) && !in_array($table,$this->filters)) continue;
if (strpos($table,'_')!==false || $table==$type) continue;
$owned = 'own'.ucfirst($table);
$shared = 'shared'.ucfirst($table);
Expand Down
6 changes: 3 additions & 3 deletions RedBean/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public static function unassociate( $beans1, $beans2 , $fast=false) {
*/
public static function related( $bean, $type, $sql=null, $values=array()) {
$keys = self::$associationManager->related( $bean, $type );
if (count($keys)==0) return array();
if (count($keys)==0 || !is_array($keys)) return array();
if (!$sql) return self::batch($type, $keys);
$rows = self::$writer->selectRecord( $type, array('id'=>$keys),array($sql,$values),false );
return self::$redbean->convertToBeans($type,$rows);
Expand All @@ -350,7 +350,7 @@ public static function related( $bean, $type, $sql=null, $values=array()) {
*/
public static function relatedOne( RedBean_OODBBean $bean, $type, $sql=null, $values=array() ) {
$beans = self::related($bean, $type, $sql, $values);
if (count($beans)==0) return null;
if (count($beans)==0 || !is_array($beans)) return null;
return reset( $beans );
}

Expand Down Expand Up @@ -927,7 +927,7 @@ public static function getColumns($table) {
* @return string $slots
*/
public static function genSlots($array) {
if (count($array)>0) {
if (is_array($array) && count($array)>0) {
$filler = array_fill(0,count($array),'?');
return implode(',',$filler);
}
Expand Down
2 changes: 1 addition & 1 deletion RedBean/OODB.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ private function processResidue($ownresidue) {
*/
private function processTrashcan($bean,$ownTrashcan) {
$myFieldLink = $bean->getMeta('type').'_id';
if (count($ownTrashcan)>0) {
if (is_array($ownTrashcan) && count($ownTrashcan)>0) {
$first = reset($ownTrashcan);
if ($first instanceof RedBean_OODBBean) {
$alias = $bean->getMeta('sys.alias.'.$first->getMeta('type'));
Expand Down
2 changes: 1 addition & 1 deletion RedBean/OODBBean.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function export($meta = false, $parents = false, $onlyMe = false, $filter
}
}
elseif ($v instanceof RedBean_OODBBean) {
if (count($filters) && !in_array(strtolower($v->getMeta('type')),$filters)) {
if (is_array($filters) && count($filters) && !in_array(strtolower($v->getMeta('type')),$filters)) {
continue;
}
$v = $v->export($meta,$parents,false,$filters);
Expand Down
2 changes: 1 addition & 1 deletion RedBean/Plugin/BeanExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function export( $beans, $resetRecur=true ) {
}

if ($this->typeShield===true) {
if (count($beans)>0) {
if (is_array($beans) && count($beans)>0) {
$firstBean = reset($beans);
$type = $firstBean->getMeta('type');
if (isset($this->recurTypeCheck[$type])){
Expand Down
5 changes: 3 additions & 2 deletions RedBean/QueryWriter/AQueryWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ public function selectRecord( $type, $conditions, $addSql=null, $delete=null, $i
$sql = $this->safeColumn($column);
$sql .= ' '.($inverse ? ' NOT ':'').' IN ( ';
//If its safe to not use bindings please do... (fixes SQLite PDO issue limit 256 bindings)
if (count($conditions)===1
if (is_array($conditions)
&& count($conditions)===1
&& isset($conditions['id'])
&& is_array($values)
&& preg_match('/^\d+$/',implode('',$values))) {
Expand Down Expand Up @@ -277,7 +278,7 @@ public function selectRecord( $type, $conditions, $addSql=null, $delete=null, $i

}
$sql = '';
if (count($sqlConditions)>0) {
if (is_array($sqlConditions) && count($sqlConditions)>0) {
$sql = implode(' AND ',$sqlConditions);
$sql = " WHERE ( $sql ) ";
if ($addSql) $sql .= " AND $addSql ";
Expand Down
2 changes: 1 addition & 1 deletion RedBean/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function tagged( $beanType, $tagList ) {
if ($tagList!==false && !is_array($tagList)) $tags = explode( ",", (string)$tagList); else $tags=$tagList;
$collection = array();
$tags = $this->redbean->find('tag',array('title'=>$tags));
if (count($tags)>0) {
if (is_array($tags) && count($tags)>0) {
$collectionKeys = $this->associationManager->related($tags,$beanType);
if ($collectionKeys) {
$collection = $this->redbean->batch($beanType,$collectionKeys);
Expand Down
2 changes: 2 additions & 0 deletions testing/RedUNIT/Mysql/Foreignkeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public function run() {
information_schema.KEY_COLUMN_USAGE ke
WHERE
ke.referenced_table_name IS NOT NULL
AND ke.CONSTRAINT_SCHEMA="oodb"
ORDER BY
constraint_name;'));

$json = '[{"parent":"genre","child":"book_genre","constraint_name":"book_genre_ibfk_1"},{"parent":"book","child":"book_genre","constraint_name":"book_genre_ibfk_2"},{"parent":"cover","child":"book","constraint_name":"cons_fk_book_cover_id_id"},{"parent":"book","child":"page","constraint_name":"cons_fk_page_book_id_id"}]';
$j1 = json_decode($j,true);
$j2 = json_decode($json,true);

foreach($j1 as $jrow) {
$s = json_encode($jrow);
$found = 0;
Expand Down

0 comments on commit 78e16a3

Please sign in to comment.