Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
- Fixed DatabaseController error
Browse files Browse the repository at this point in the history
- Formatting & code clean up
- Merge branch 'master' of github.com:Protoqol/Prequel
  • Loading branch information
Quinten Justus committed Jun 27, 2020
2 parents 68e429a + 15cd3cb commit b06d384
Show file tree
Hide file tree
Showing 34 changed files with 653 additions and 700 deletions.
2 changes: 0 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
</a>
</p>

## Development temporarily on hold

#### [TL;DR? Test Prequel here!](https://prequel.protoqol.xyz/prequel)

#### What is Prequel exactly?
Expand Down
38 changes: 19 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"name": "protoqol/prequel",
"description": "Clear and concise database management.",
"type": "library",
"license": "MIT",
"authors": [
"name" : "protoqol/prequel",
"description" : "Clear and concise database management.",
"type" : "library",
"license" : "MIT",
"authors" : [
{
"name": "Quinten Schorsij",
"name" : "Quinten Schorsij",
"email": "quinten@protoqol.xyz"
}
],
"minimum-stability": "stable",
"require": {
"php": "^7.1",
"minimum-stability" : "stable",
"require" : {
"php" : "^7.1",
"laravel/framework": ">=5.6"
},
"extra": {
"extra" : {
"laravel": {
"providers": [
"Protoqol\\Prequel\\PrequelServiceProvider"
]
}
},
"require-dev": {
"require-dev" : {
"orchestra/testbench": "^3.7",
"phpmd/phpmd": "^2.6"
"phpmd/phpmd" : "^2.6"
},
"autoload": {
"autoload" : {
"psr-4": {
"Protoqol\\Prequel\\": "src"
}
},
"autoload-dev": {
"autoload-dev" : {
"psr-4": {
"Protoqol\\Prequel\\Tests\\": "tests/"
}
},
"scripts": {
"scripts" : {
"phpins": [
"./vendor/bin/phpinsights"
],
"phpmd": [
"phpmd" : [
"phpmd src html cleancode,codesize,controversial,design,naming,unusedcode > public/phpmd.html"
],
"test": [
"test" : [
"phpunit"
]
},
"scripts-descriptions": {
"phpins": "Runs nunomaduro's PHPInsights. This gives you a report about the current code quality.",
"phpmd": "Runs PHPMD based on original configuration. You can find the new mess detector report at http://localhost/vendor/prequel/phpmd.html Note that 'Avoid using static access to class' errors should be ignored.",
"test": "Runs the default PHPUnit test suite configured in phpunit.xml"
"phpmd" : "Runs PHPMD based on original configuration. You can find the new mess detector report at http://localhost/vendor/prequel/phpmd.html Note that 'Avoid using static access to class' errors should be ignored.",
"test" : "Runs the default PHPUnit test suite configured in phpunit.xml"
}
}
8 changes: 4 additions & 4 deletions resources/assets/js/components/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</template>

<script>
import Management from './DashboardElements/Management'
import Management from './DashboardElements/Management';
export default {
name : 'Dashboard',
components: { Management },
}
name: 'Dashboard',
components: {Management},
};
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
return {
migrations: {
pending: 0,
total : 0,
total: 0,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<!-- @TODO edit config -->
<!-- @TODO edit config -->
</template>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<script>
export default {
name : 'StatusDisplay',
name: 'StatusDisplay',
props: ['header', 'value', 'unit'],
};
</script>
Expand Down
35 changes: 18 additions & 17 deletions src/App/AppStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,38 @@

/**
* Class AppStatus
*
* @package Protoqol\Prequel\App
*/
class AppStatus
{

/**
* Holds Prequel's database connection.
*
* @var \Illuminate\Database\Connection
*/
private $connection;

/**
* Holds database traverser instance.
*
* @var \Protoqol\Prequel\Database\DatabaseTraverser $traverser
*/
private $traverser;

/**
* AppStatus constructor.
*/
public function __construct()
{
public function __construct() {
$this->traverser = new DatabaseTraverser();
$this->connection = (new DatabaseConnector())->getConnection();
}

/**
* @return array
*/
public function getStatus(): array
{
public function getStatus() : array {
return [
'migrations' => (new MigrationAction('', ''))->pending(),
'serverInfo' => $this->serverInfo(),
Expand All @@ -48,33 +49,33 @@ public function getStatus(): array

/**
* Get server info.
*
* @return array
*/
private function serverInfo(): array
{
private function serverInfo() : array {
return $this->connection->getServerInfo();
}

/**
* Check database permissions for current user.
*
* @return array
*/
public function userPermissions(): array
{
public function userPermissions() : array {

$grants = $this->connection->getGrants();
$privs = (string)array_values($grants)[0];
$privs = (string) array_values($grants)[0];
$permissions = [];

// If anyone seeing this has a better way of checking this, be my guest!
$permissions['SELECT'] = (bool)preg_match('(SELECT)', $privs);
$permissions['INSERT'] = (bool)preg_match('(INSERT)', $privs);
$permissions['UPDATE'] = (bool)preg_match('(UPDATE)', $privs);
$permissions['DELETE'] = (bool)preg_match('(DELETE)', $privs);
$permissions['FILE'] = (bool)preg_match('(FILE)', $privs);
$permissions['CREATE'] = (bool)preg_match('(CREATE)', $privs);
$permissions['DROP'] = (bool)preg_match('(DROP)', $privs);
$permissions['ALTER'] = (bool)preg_match('(ALTER)', $privs);
$permissions['SELECT'] = (bool) preg_match('(SELECT)', $privs);
$permissions['INSERT'] = (bool) preg_match('(INSERT)', $privs);
$permissions['UPDATE'] = (bool) preg_match('(UPDATE)', $privs);
$permissions['DELETE'] = (bool) preg_match('(DELETE)', $privs);
$permissions['FILE'] = (bool) preg_match('(FILE)', $privs);
$permissions['CREATE'] = (bool) preg_match('(CREATE)', $privs);
$permissions['DROP'] = (bool) preg_match('(DROP)', $privs);
$permissions['ALTER'] = (bool) preg_match('(ALTER)', $privs);
$permissions['HAS_ALL'] = true;

// Check if user has all needed permissions
Expand Down
42 changes: 21 additions & 21 deletions src/App/ConfigWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@
class ConfigWriter
{

public function toFile(string $filePath, array $newValues, bool $useValidation = true): string
{
/**
* Write to config file
*
* @param string $filePath
* @param array $newValues
* @param bool $useValidation
*
* @return string
*/
public function toFile(string $filePath, array $newValues, bool $useValidation = true) : string {
$contents = file_get_contents($filePath);

try {
Expand All @@ -38,8 +46,7 @@ public function toFile(string $filePath, array $newValues, bool $useValidation =
return $contents;
}

public function toContent(string $contents, array $newValues, bool $useValidation = true): string
{
public function toContent(string $contents, array $newValues, bool $useValidation = true) : string {
$contents = $this->parseContent($contents, $newValues);

if (!$useValidation) {
Expand All @@ -57,7 +64,7 @@ public function toContent(string $contents, array $newValues, bool $useValidatio
throw new Exception(sprintf('Unable to rewrite key "%s" in config, does it exist?', $key));
}

$array = $array[$part];
$array = $array[ $part ];
}
$actualValue = $array;

Expand All @@ -69,8 +76,7 @@ public function toContent(string $contents, array $newValues, bool $useValidatio
return $contents;
}

protected function parseContent(string $contents, array $newValues): string
{
protected function parseContent(string $contents, array $newValues) : string {
$result = $contents;

foreach ($newValues as $path => $value) {
Expand All @@ -80,8 +86,7 @@ protected function parseContent(string $contents, array $newValues): string
return $result;
}

protected function parseContentValue(string $contents, string $path, $value): string
{
protected function parseContentValue(string $contents, string $path, $value) : string {
$result = $contents;
$items = explode('.', $path);
$key = array_pop($items);
Expand All @@ -105,8 +110,8 @@ protected function parseContentValue(string $contents, string $path, $value): st
return $result;
}

protected function writeValueToPhp($value): string
{
protected function writeValueToPhp($value) : string {
if (is_string($value) && strpos($value, "'") === false) {
$replaceValue = "'" . $value . "'";
} elseif (is_string($value) && strpos($value, '"') === false) {
Expand All @@ -126,8 +131,7 @@ protected function writeValueToPhp($value): string
return $replaceValue;
}

protected function writeArrayToPhp(array $array): array
{
protected function writeArrayToPhp(array $array) : array {
$result = [];

foreach ($array as $value) {
Expand All @@ -141,8 +145,7 @@ protected function writeArrayToPhp(array $array): array
return $result;
}

protected function buildStringExpression(string $targetKey, array $arrayItems = [], string $quoteChar = "'"): string
{
protected function buildStringExpression(string $targetKey, array $arrayItems = [], string $quoteChar = "'") : string {
$expression = [];

// Opening expression for array items ($1)
Expand All @@ -163,8 +166,7 @@ protected function buildStringExpression(string $targetKey, array $arrayItems =
/**
* Common constants only (true, false, null, integers)
*/
protected function buildConstantExpression(string $targetKey, array $arrayItems = []): string
{
protected function buildConstantExpression(string $targetKey, array $arrayItems = []) : string {
$expression = [];

// Opening expression for array items ($1)
Expand All @@ -182,8 +184,7 @@ protected function buildConstantExpression(string $targetKey, array $arrayItems
/**
* Single level arrays only
*/
protected function buildArrayExpression(string $targetKey, array $arrayItems = []): string
{
protected function buildArrayExpression(string $targetKey, array $arrayItems = []) : string {
$expression = [];

// Opening expression for array items ($1)
Expand All @@ -198,8 +199,7 @@ protected function buildArrayExpression(string $targetKey, array $arrayItems = [
return '/' . implode('', $expression) . '/';
}

protected function buildArrayOpeningExpression(array $arrayItems): string
{
protected function buildArrayOpeningExpression(array $arrayItems) : string {
if (count($arrayItems)) {
$itemOpen = [];
foreach ($arrayItems as $item) {
Expand Down
Loading

0 comments on commit b06d384

Please sign in to comment.