Skip to content

Latest commit

 

History

History

php

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Code Detector API - PHP Package

Code Detector identifies the programming language of any submitted code snippet. It returns the canonical language name, readable title, and standard file extension for the detected code.

Installation

Install via Composer:

composer require apiverve/codedetector

Getting Started

Get your API key at APIVerve

Basic Usage

<?php

require_once 'vendor/autoload.php';

use APIVerve\Codedetector\Client;

// Initialize the client
$client = new Client('YOUR_API_KEY');

// Make a request
$response = $client->execute(['code' => 'a = 5
b = 6
c = 7

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print(\'The area of the triangle is %0.2f\' %area)']);

// Print the response
print_r($response);

Error Handling

use APIVerve\Codedetector\Client;
use APIVerve\Codedetector\Exceptions\APIException;
use APIVerve\Codedetector\Exceptions\ValidationException;

try {
    $response = $client->execute(['code' => 'a = 5
b = 6
c = 7

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print(\'The area of the triangle is %0.2f\' %area)']);
    print_r($response['data']);
} catch (ValidationException $e) {
    echo "Validation error: " . implode(', ', $e->getErrors());
} catch (APIException $e) {
    echo "API error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
}

Debug Mode

// Enable debug logging
$client = new Client(
    apiKey: 'YOUR_API_KEY',
    debug: true
);

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "likelihood": 0.99,
    "family": "PYTHON",
    "current": "python",
    "readable": "Python Code",
    "extension": ".py",
    "paradigm": "multi-paradigm",
    "isCompiled": false
  }
}

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client

Documentation

For more information, visit the API Documentation.

Support

License

This package is available under the MIT License.