Skip to content
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
26 changes: 10 additions & 16 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,25 @@
"plugin:cypress/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"prettier/prettier": "warn",
"import/no-unresolved": 0,
"@typescript-eslint/ban-ts-comment": "off",
"camelcase": "off"
},
"overrides":
[{
"files": ["*.jsx"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": ["off"]
}
}],
"overrides": [
{
"files": ["*.jsx"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": ["off"]
}
}
],
"settings": {
"import/resolver": {
"alias": {
"map": [
[
"src",
"./src"
],
]
"map": [["src", "./src"]]
}
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
build
vendor
yarn-error.log
.phpunit.result.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"scripts": {
"lint:php": "phpcs .",
"lint:php-fix": "phpcbf .",
"test:php": "phpunit --dont-report-useless-tests --configuration ./phpunit.xml.dist"
"test:php": "phpunit --dont-report-useless-tests --configuration ./phpunit.xml --testdox"
}
}
7 changes: 0 additions & 7 deletions helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
*/
class Helper {

/**
* Name of flag environment.
*
* @var string $env_option_name
*/
public static $env_option_name = 'mr_feature_flags_env';

/**
* Flag search helper.
*
Expand Down
156 changes: 0 additions & 156 deletions includes/Api/FlagOptions.php

This file was deleted.

101 changes: 101 additions & 0 deletions includes/Api/Flags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* API class for feature flags options
*
* @package mr-feature-flags
* @since 1.0.0
*/

declare(strict_types=1);

namespace MR\FeatureFlags\Api;

/**
* Class Settings
*
* @package mr-feature-flags
* @since 1.0.0
*/
class Flags {

/**
* Name in options table.
*
* @var string $option_name
*/
public static $option_name = 'mr_feature_flags';

/**
* Register feature flag endpoints.
*
* @return void
* @since 1.0.0
*/
public function register_flags_endpoints() {
add_action(
'rest_api_init',
function () {
register_rest_route(
'feature-flags/v1',
'flags',
[
[
'methods' => \WP_REST_SERVER::READABLE,
'callback' => [ $this, 'get_all_flags' ],
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
],
[
'methods' => \WP_REST_SERVER::EDITABLE,
'callback' => [ $this, 'post_flags' ],
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
],
]
);
}
);
}

/**
* Get all flags from options
*
* @return mixed List of flags.
*/
public function get_all_flags() {
$flags = get_option( self::$option_name );

if ( empty( $flags ) ) {
return rest_ensure_response( [] );
}

return rest_ensure_response( $flags );
}

/**
* Insert / Update flags in options table.
*
* @param WP_Request $request API request.
*
* @return mixed List of flags.
*/
public function post_flags( $request ) {
$flags = $request->get_json_params();

if ( is_array( $flags ) ) {
$result = update_option( self::$option_name, $flags );
return rest_ensure_response(
array(
'status' => 200,
'success' => true,
),
);

} else {
return new \WP_Error( 'invalid_input', 'Cannot update flags', array( 'status' => 400 ) );
}
}

}
4 changes: 2 additions & 2 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function register_feature_settings() {
public function register_settings() {

add_menu_page(
'Feature Flags',
'Feature Flags',
__( 'Feature Flags', 'mr-feature-flags' ),
__( 'Feature Flags', 'mr-feature-flags' ),
'manage_options',
'mr-feature-flags',
[ $this, 'render_page' ],
Expand Down
6 changes: 3 additions & 3 deletions includes/FeatureFlags.php → includes/Utils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This is the init file for the plugin
* Utility class to expose flag methods.
*
* @package mr-feature-flags
* @since 1.0.0
Expand All @@ -11,12 +11,12 @@
namespace MR\FeatureFlags;

/**
* Class FeatureFlags
* Class Utils
*
* @package mr-feature-flags
* @since 1.0.0
*/
class FeatureFlags {
class Utils {

/**
* Name in options table.
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests/Unit/</directory>
</testsuite>

</testsuites>
</phpunit>
Loading