Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to PSR12 code style #15

Merged
merged 3 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,227 changes: 591 additions & 636 deletions administrator/components/com_installer/src/Model/UpdateModel.php

Large diffs are not rendered by default.

240 changes: 119 additions & 121 deletions libraries/src/TUF/DatabaseStorage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Joomla! Content Management System
*
Expand All @@ -20,125 +21,122 @@
*/
class DatabaseStorage implements \ArrayAccess
{
/**
* The Tuf table object
*
* @var Table
*/
protected $table;

/**
* Initialize the DatabaseStorage class
*
* @param DatabaseDriver $db A database connector object
* @param integer $extensionId The extension ID where the storage should be implemented for
*/
public function __construct(DatabaseDriver $db, int $extensionId)
{
$this->table = new Tuf($db);

$this->table->load(['extension_id' => $extensionId]);
}

/**
* Check if an offset/table column exists
*
* @param mixed $offset The offset/database column to check for
*
* @return boolean
*/
public function offsetExists($offset): bool
{
$column = $this->getCleanColumn($offset);

return substr($column, -5) === '_json' && $this->table->hasField($column) && !is_null($this->table->$column);
}

/**
* Check if an offset/table column exists
*
* @param mixed $offset The offset/database column to check for
*
* @return boolean
*/
public function tableColumnExists($offset): bool
{
$column = $this->getCleanColumn($offset);

return substr($column, -5) === '_json' && $this->table->hasField($column);
}

/**
* Get the value of a table column
*
* @param mixed $offset The column name to get the value for
*
* @return mixed
*/
public function offsetGet($offset)
{
if (!$this->offsetExists($offset))
{
throw new RoleNotFoundException;
}

$column = $this->getCleanColumn($offset);

return $this->table->$column;
}

/**
* Set a value in a column
*
* @param [type] $offset The table column to set the value
* @param [type] $value The value to set
*
* @return void
*/
public function offsetSet($offset, $value)
{
if (!$this->tableColumnExists($offset))
{
throw new RoleNotFoundException;
}

$column = $this->getCleanColumn($offset);

$this->table->$column = $value;

$this->table->store();
}

/**
* Reset the value to a
*
* @param mixed $offset The table column to reset the value to null
*
* @return void
*/
public function offsetUnset($offset): void
{
if (!$this->offsetExists($offset))
{
throw new RoleNotFoundException;
}

$column = $this->getCleanColumn($offset);

$this->table->$column = null;

$this->table->store(true);
}

/**
* Convert file names to table columns
*
* @param string $name The original file name
*
* @return string
*/
protected function getCleanColumn($name): string
{
return str_replace('.', '_', $name);
}
/**
* The Tuf table object
*
* @var Table
*/
protected $table;

/**
* Initialize the DatabaseStorage class
*
* @param DatabaseDriver $db A database connector object
* @param integer $extensionId The extension ID where the storage should be implemented for
*/
public function __construct(DatabaseDriver $db, int $extensionId)
{
$this->table = new Tuf($db);

$this->table->load(['extension_id' => $extensionId]);
}

/**
* Check if an offset/table column exists
*
* @param mixed $offset The offset/database column to check for
*
* @return boolean
*/
public function offsetExists($offset): bool
{
$column = $this->getCleanColumn($offset);

return substr($column, -5) === '_json' && $this->table->hasField($column) && !is_null($this->table->$column);
}

/**
* Check if an offset/table column exists
*
* @param mixed $offset The offset/database column to check for
*
* @return boolean
*/
public function tableColumnExists($offset): bool
{
$column = $this->getCleanColumn($offset);

return substr($column, -5) === '_json' && $this->table->hasField($column);
}

/**
* Get the value of a table column
*
* @param mixed $offset The column name to get the value for
*
* @return mixed
*/
public function offsetGet($offset)
{
if (!$this->offsetExists($offset)) {
throw new RoleNotFoundException();
}

$column = $this->getCleanColumn($offset);

return $this->table->$column;
}

/**
* Set a value in a column
*
* @param [type] $offset The table column to set the value
* @param [type] $value The value to set
*
* @return void
*/
public function offsetSet($offset, $value)
{
if (!$this->tableColumnExists($offset)) {
throw new RoleNotFoundException();
}

$column = $this->getCleanColumn($offset);

$this->table->$column = $value;

$this->table->store();
}

/**
* Reset the value to a
*
* @param mixed $offset The table column to reset the value to null
*
* @return void
*/
public function offsetUnset($offset): void
{
if (!$this->offsetExists($offset)) {
throw new RoleNotFoundException();
}

$column = $this->getCleanColumn($offset);

$this->table->$column = null;

$this->table->store(true);
}

/**
* Convert file names to table columns
*
* @param string $name The original file name
*
* @return string
*/
protected function getCleanColumn($name): string
{
return str_replace('.', '_', $name);
}
}
1 change: 1 addition & 0 deletions libraries/src/TUF/Exception/RoleNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Joomla! Content Management System
*
Expand Down
Loading