Mojopollo\Schema\Commands\MakeMigrationJsonCommand::validate PHP Method

validate() protected method

Validate the json file and console report any issues
protected validate ( ) : void
return void
    protected function validate()
    {
        // Get json array from file
        $jsonArray = $this->makeMigrationJson->jsonFileToArray($this->filePath);
        // Check for invalid json
        if ($jsonArray === null) {
            // Display error message
            $this->error('Invalid JSON detected: Check that your json file does not contain invalid syntax: ' . $this->filePath);
            // End further execution
            return;
        }
        // Check for data existence
        if (empty($jsonArray)) {
            // Display error message
            $this->error('No data found in json file: It seems you have no data in: ' . $this->filePath);
            // End further execution
            return;
        }
        // Validate
        $errors = $this->makeMigrationJson->validateSchema($jsonArray);
        // If no errors where found
        if (empty($errors)) {
            // Display confirmation message
            $this->info('No validation errors where found, congrats!');
            // End further execution
            return;
        }
        // Report results
        foreach ($errors as $tableName => $fields) {
            // For every field
            foreach ($fields as $fieldName => $fieldProperties) {
                // For every field property
                foreach ($fieldProperties as $property) {
                    // Show error
                    $this->error($property);
                    // Show json reference
                    $this->error("In section: " . json_encode([$tableName => [$fieldName => $jsonArray[$tableName][$fieldName]]], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
                }
            }
        }
    }