How about this?

```php
	/**
	 * Returns the number of records.
	 * @param string $q the COUNT expression. Defaults to '*'.
	 * Make sure you properly quote column names in the expression.
	 * @param Connection $db the database connection used to generate the SQL statement.
	 * If this parameter is not given (or null), the `db` application component will be used.
	 * To match the method signature required by [[QueryInterface]], the database connection
	 * can be given as the first parameter. `$q` is considered default ('*') in this case.
	 * @return integer number of records
	 */
	public function count($q = '*', $db = null)
	{
		if ($q instanceof Connection) {
			$db = $q;
			$q = '*';
		}
		$this->select = ["COUNT($q)"];
		return $this->createCommand($db)->queryScalar();
	}
```