Skip to content

Commit

Permalink
Fixed code-sniffer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cmacmackin committed Nov 19, 2023
1 parent 4ebe1fc commit e1da59c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 63 deletions.
7 changes: 6 additions & 1 deletion meta/AccessTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,12 @@ protected function buildGetDataSQL($idColumn = 'pid')

foreach ($this->schema->getColumns(false) as $col) {
$col->getType()->select(
$QB, 'DATA', $mtable, 'out' . $col->getColref(), false, $sep
$QB,
'DATA',
$mtable,
'out' . $col->getColref(),
false,
$sep
);
}

Expand Down
9 changes: 5 additions & 4 deletions meta/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function addSchema($table, $alias = '', $joinon = array())
);
}
if ($joinon[1] != '=') {
throw new StructException('Only equality comparison is supported for JOIN conditions');
throw new StructException('Only equality comparison is supported for JOIN conditions');
}
$this->joins[$schema->getTable()] = $this->getJoinColumns($schema, $joinon[0], $joinon[2]);
}
Expand All @@ -125,13 +125,14 @@ public function addSchema($table, $alias = '', $joinon = array())
* Returns the columns being matched against for a JOIN ... ON
* expression. The result will be ordered such that the first
* column is the one from a previously-joined schema.
*
*
* @param Schema $schema The schema being JOINed to the query
* @param string $left The LHS of the JOIN ON comparison
* @param string $right the RHS of the JOIN ON comparison
* @return array The first element is the LHS column object and second is the RHS
*/
protected function getJoinColumns($schema, $left, $right) {
protected function getJoinColumns($schema, $left, $right)
{
$lcol = $this->findColumn($left);
if ($lcol === false) {
throw new StructException('Unrecognoside field ' . $left);
Expand All @@ -143,7 +144,7 @@ protected function getJoinColumns($schema, $left, $right) {
$table = $schema->getTable();
$left_is_old_table = $lcol->getTable() != $table;
if ($left_is_old_table == ($rcol->getTable() != $table)) {
throw new StructException("Exactly one side of ON condition $left = $right must be a column of $table" );
throw new StructException("Exactly one side of ON condition $left = $right must be a column of $table");
}
if ($left_is_old_table) {
return array($lcol, $rcol);
Expand Down
6 changes: 2 additions & 4 deletions meta/SearchCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public function getSQL()
$QB->filters()->where('AND', 'tag IS NOT \'\'');

$col = $this->columns[0];
$col->getType()->select(
$QB, 'data_' . $datatable, 'multi_' . $col->getTable(), 'tag', true
);

$col->getType()->select($QB, 'data_' . $datatable, 'multi_' . $col->getTable(), 'tag', true);

$QB->addSelectStatement('COUNT(tag)', 'count');
$QB->addSelectColumn('schema_assignments', 'assigned', 'ASSIGNED');
if ($col->isMulti()) {
Expand Down
16 changes: 12 additions & 4 deletions meta/SearchSQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public function addSchemas($schemas, $joins)
$lefttable = 'data_' . $lcol->getTable();
$righttable = 'data_' . $rcol->getTable();
$on = $lcol->getType()->joinCondition(
$this->qb, $lefttable, $lcol->getColName(), $righttable,
$rcol->getColName(), $rcol->getType()
$this->qb,
$lefttable,
$lcol->getColName(),
$righttable,
$rcol->getColName(),
$rcol->getType()
);
$this->qb->addLeftJoin($lefttable, $righttable, $righttable, $on);
}
Expand Down Expand Up @@ -100,8 +104,12 @@ public function addColumns($columns)
$n = 0;
foreach ($columns as $col) {
$col->getType()->select(
$this->qb, 'data_' . $col->getTable(), 'multi_' . $col->getTable(),
'C' . $n++, true, $sep
$this->qb,
'data_' . $col->getTable(),
'multi_' . $col->getTable(),
'C' . $n++,
true,
$sep
);
}
}
Expand Down
30 changes: 18 additions & 12 deletions types/AbstractBaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ public function renderTagCloudLink($value, \Doku_Renderer $R, $mode, $page, $fil
* @param bool $test_rid Whether to require RIDs to be equal in the JOIN condition
* @return string Alias for the multi-table
*/
public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $test_rid = true) {
public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $test_rid = true)
{
$MN = $QB->generateTableAlias('M');
$condition = "$datatable.pid = $MN.pid ";
if ($test_rid) $condition .= "AND $datatable.rid = $MN.rid ";
Expand All @@ -384,7 +385,7 @@ public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $t
);
return $MN;
}

/**
* This function is used to modify an aggregation query to add a filter
* for the given column matching the given value. A type should add at
Expand Down Expand Up @@ -432,14 +433,14 @@ public function filter(QueryBuilderWhere $add, $tablealias, $colname, $comp, $va
* need to add additional logic to the conditional expression or make
* additional JOINs.
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string|array The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
return "$tablealias.$colname";
}

Expand All @@ -452,7 +453,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
* @param string $value The value a column is being compared to
* @return string A SQL expression processing the value in some way.
*/
protected function getSqlConstantValue($value) {
protected function getSqlConstantValue($value)
{
return $value;
}

Expand All @@ -477,8 +479,11 @@ public function joinCondition($QB, $left_table, $left_colname, $right_table, $ri
$add = new QueryBuilderWhere($QB);
$op = 'AND';
$lhs = $this->getSqlCompareValue($add, $left_table, $left_colname, $op);
$rhs = $this->getSqlConstantValue($right_coltype->getSqlCompareValue($add, $right_table, $right_colname, $op));
// FIXME: Need to handle possibility of getSqlCompareValue returning multiple values (i.e., due to joining on page name)
$rhs = $this->getSqlConstantValue(
$right_coltype->getSqlCompareValue($add, $right_table, $right_colname, $op)
);
// FIXME: Need to handle possibility of getSqlCompareValue returning multiple
// values (i.e., due to joining on page name)
// FIXME: Need to consider how/whether to handle multi-valued columns
$AN = $add->getQB()->generateTableAlias('A');
$subquery = "(SELECT assigned
Expand Down Expand Up @@ -506,10 +511,11 @@ public function joinCondition($QB, $left_table, $left_colname, $right_table, $ri
* @param string $colname Name of the column being JOINed ON
* @return string One side of the equality comparion being used for the JOIN
*/
protected function joinArgument(QueryBuilderWhere $add, $table, $colname) {
protected function joinArgument(QueryBuilderWhere $add, $table, $colname)
{
return "$table.$colname";
}

/**
* Add the proper selection for this type to the current Query. Handles the
* possibility of multi-valued columns.
Expand All @@ -519,7 +525,7 @@ protected function joinArgument(QueryBuilderWhere $add, $table, $colname) {
* @param string $multitable The name of the table the values are stored in if the column is multi-valued
* @param string $alias The added selection *has* to use this column alias
* @param bool $test_rid Whether to require RIDs to be equal if JOINing multi-table
* @param string|null $concat_sep Seperator to concatenate mutli-values together. If null, don't perform concatentation.
* @param string|null $concat_sep Seperator to concatenate mutli-values together. Don't concatenate if null.
*/
public function select(QueryBuilder $QB, $singletable, $multitable, $alias, $test_rid = true, $concat_sep = null)
{
Expand Down
10 changes: 5 additions & 5 deletions types/AutoSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order)
/**
* When using `%lastsummary%`, we need to compare against the `title` table.
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
$QB = $add->getQB();
$rightalias = $QB->generateTableAlias();
$QB->addLeftJoin($tablealias, 'titles', $rightalias, "$tablealias.pid = $rightalias.pid");

return "$rightalias.lastsummary";
}
}
}
13 changes: 7 additions & 6 deletions types/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,18 @@ public function selectCol(QueryBuilder $QB, $tablealias, $colname, $alias)


/**
* Handle case of a revision column, where you need to convert from a Unix
* Handle case of a revision column, where you need to convert from a Unix
* timestamp.
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @return string The SQL expression to be used on one side of the comparison operator
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string|array The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
$col = "$tablealias.$colname";
$QB = $add->getQB();

Expand All @@ -141,7 +142,7 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,

return $col;
}

/**
* When sorting `%lastupdated%`, then sort the data from the `titles` table instead the `data_` table.
*
Expand Down
7 changes: 4 additions & 3 deletions types/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order)
/**
* Decimals need to be casted to proper type for comparison
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
Expand All @@ -174,7 +174,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $col
* @param string $value The value a column is being compared to
* @return string SQL expression casting $value to a decimal
*/
protected function getSqlConstantValue($value) {
protected function getSqlConstantValue($value)
{
return "CAST($value AS DECIMAL)";
}

Expand Down
11 changes: 6 additions & 5 deletions types/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ public function selectCol(QueryBuilder $QB, $tablealias, $colname, $alias)
/**
* Compare against lookup table
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string|array The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
$schema = 'data_' . $this->config['schema'];
$column = $this->getLookupColumn();
if (!$column) {
Expand All @@ -290,7 +290,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
* @param string $value The value a column is being compared to
* @return string A SQL expression processing the value in some way.
*/
protected function getSqlConstantValue($value) {
protected function getSqlConstantValue($value)
{
$schema = 'data_' . $this->config['schema'];
$column = $this->getLookupColumn();
if (!$column) {
Expand Down
9 changes: 4 additions & 5 deletions types/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,13 @@ public function displayValue($value)
/**
* When using titles, we need to compare against the title table, too.
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return array The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op)
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
if (!$this->config['usetitles']) {
return parent::getSqlCompareValue($add, $tablealias, $colname, $op);
Expand Down Expand Up @@ -272,6 +271,6 @@ protected function mergeConfig($current, &$config)
// if (!$this->config['usetitles']) {
// return parent::joinArgument($add, $table, $colname);
// }
// // FIXME: How to handle multiple values
// // FIXME: How to handle multiple values
// }
}
11 changes: 6 additions & 5 deletions types/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ protected function buildSQLFromContext(Column $context)
/**
* Normalize tags before comparing
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
return "LOWER(REPLACE($tablealias.$colname, ' ', ''))";
}

Expand All @@ -132,7 +132,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
* @param string $value The value a column is being compared to
* @return string A SQL expression processing the value in some way.
*/
protected function getSqlConstantValue($value) {
protected function getSqlConstantValue($value)
{
return "LOWER(REPLACE($value, ' ', ''))";
}
}
8 changes: 4 additions & 4 deletions types/TraitFilterPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ trait TraitFilterPrefix
/**
* Comparisons are done against the full string (including prefix/postfix)
*
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string|array The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
$column = parent::getSqlCompareValue($add, $tablealias, $colname, $op);

$add = $add->where($op); // open a subgroup
Expand Down
9 changes: 4 additions & 5 deletions types/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order)
}

/**
* @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in
* @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in
* @param string $tablealias The table the values are stored in
* @param string $colname The column name on the above table
* @param string &$op the logical operator this filter shoudl use
* @param string &$op the logical operator this filter should use
* @return string The SQL expression to be used on one side of the comparison operator
*/
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,
$colname, &$op) {
protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op)
{
if (is_a($this->context, 'dokuwiki\plugin\struct\meta\UserColumn')) {
$QB = $add->getQB();
$rightalias = $QB->generateTableAlias();
Expand All @@ -156,5 +156,4 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias,

return parent::getSqlCompareValue($add, $tablealias, $colname, $comp, $value, $op);
}

}

0 comments on commit e1da59c

Please sign in to comment.