PHPackages                             emleons/sim-rating - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. emleons/sim-rating

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

emleons/sim-rating
==================

A simple 5-star rating system for CodeIgniter 4

v2.1.2(9mo ago)154MITPHPCI passing

Since Jul 26Pushed 9mo agoCompare

[ Source](https://github.com/emleonstz/sim-rating)[ Packagist](https://packagist.org/packages/emleons/sim-rating)[ RSS](/packages/emleons-sim-rating/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

 [![sim-rating](src/img/banner-min.png)](src/img/banner-min.png)

Sim-Rating - A Simple 5-Star Rating System for PHP
==================================================

[](#sim-rating---a-simple-5-star-rating-system-for-php)

[![Latest Version](https://camo.githubusercontent.com/658ba7b08211bfbbaabe8bc0cc8214edf7faa72ed5fbd79a61cf1af8a0cc5f37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d6c656f6e732f73696d2d726174696e672e737667)](https://packagist.org/packages/emleons/sim-rating)[![Tests](https://github.com/emleonstz/sim-rating/actions/workflows/tests.yml/badge.svg?event=push)](https://github.com/emleonstz/sim-rating/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/b5fd47bc12a0e2afc9eb9209d4c643fa069012c7b3c426771745529009da4902/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f656d6c656f6e73747a2f73696d2d726174696e672e737667)](https://github.com/emleonstz/sim-rating/blob/main/LICENSE)

Sim-Rating is a lightweight,PHP library for displaying and calculating 5-star ratings. It supports multiple display formats (stars, bars, JSON) and is highly customizable and works with any php frame work.

### Default Star Rating

[](#default-star-rating)

[![5-star rating display](src/img/s2.png)](src/img/s2.png)---

### Custom Bar Rating

[](#custom-bar-rating)

[![Bar rating display](src/img/s1.png)](src/img/s1.png)

Features
--------

[](#features)

- 🎯 Works with PHP Framework and PHP plain implementation
- ⭐ Multiple output formats (HTML, JSON, SVG)
- 🎨 Customizable colors, sizes and styles
- 📊 Calculate averages, totals and distributions
- 📱 Responsive and mobile-friendly
- ✅ 100% unit tested

Installation
------------

[](#installation)

Install via Composer:

```
composer require emleons/sim-rating
```

### 🌟 Basic Implementation

[](#-basic-implementation)

```
require('vendor/autoload.php');
use Emleons\SimRating\Rating;

// Initialize with rating counts (all keys required)
$ratings = [
    'one_star' => 10,    // Required
    'two_star' => 20,    // Required
    'three_star' => 30,  // Required
    'four_star' => 40,   // Required
    'five_star' => 50    // Required
];

$rating = new Rating($ratings);

// Display 5-star rating
echo $rating->render(); // Defaults to HTML stars
```

### 📊 Output Formats

[](#-output-formats)

```
// As interactive HTML stars
echo $rating->render('html', [
    'interactive' => true
]);

// As JSON data
$jsonOutput = $rating->render('json');
// {
//   "average": 3.67,
//   "total": 150,
//   "distribution": {
//     "five_star": 33.33,
//     "four_star": 26.67,
//     ...
//   }
// }

// As percentage bars
echo $rating->render('html', [
    'type' => 'bars',
    'bar_height' => '25px'
]);
```

### 🎨 Customization Options

[](#-customization-options)

#### Star Display Options

[](#star-display-options)

```
new Rating($ratings, [
    'type' => 'stars',       // Display type
    'color' => '#6a5acd',    // Star color
    'size' => '1.5rem',      // Size
    'show_average' => false, // Hide average
    'show_total' => true     // Show count
]);
```

#### Bar Display Options

[](#bar-display-options)

```
new Rating($ratings, [
    'type' => 'bars',
    'color' => '#4a90e2',          // Bar color
    'bar_height' => '20px',        // Bar thickness
    'bar_show_percentages' => true,// Show percentages
    'show_summary' => true         // Show summary
]);
```

### ⚙️ All Configuration Options

[](#️-all-configuration-options)

OptionTypeRequiredDefaultDescription`type`stringYes`stars``stars` or `bars``color`stringYes`#ffc107`Main color`size`stringYes`1em`Display size`show_average`boolNo`true`Show average rating`show_total`boolNo`true`Show total ratings`show_summary`boolYes`false`Show summary text`interactive`boolYes`false`Make ratings clickable`bar_height`stringNo`20px`Bar thickness`bar_spacing`stringNo`8px`Space between bars`bar_show_percentages`boolNo`true`Show percentages### 🔄 Updating Options

[](#-updating-options)

```
$rating->setOptions([
    'color' => '#e74c3c', // Change to red
    'size' => '2rem',     // Larger size
    'type' => 'bars'      // Switch to bars
]);

// Get current options
$currentOptions = $rating->getOptions();
```

#### Laravel Blade

[](#laravel-blade)

```
@php
    $rating = new \Emleons\SimRating\Rating($product->ratings, [
        'interactive' => true,
        'show_summary' => false
    ]);
@endphp

{!! $rating->render() !!}
```

### 💡 Important Tips

[](#-important-tips)

1. Always include all 5 star rating keys
2. Set `show_summary` based on your display needs
3. Use `interactive` only when you need user ratings
4. For bars, customize heights and spacing to match your design

### 🚨 Common Errors

[](#-common-errors)

```
// ❌ Missing required keys
$invalidRatings = [
    'one_star' => 10,
    // Missing other star counts
];

// ❌ Invalid color format
new Rating($ratings, ['color' => 'red']); // Use hex codes

// ❌ Wrong option name
new Rating($ratings, ['colour' => '#fff']); // Should be 'color'
```

Display Types
-------------

[](#display-types)

### Stars

[](#stars)

```
echo $rating->render('html'); // Default star display
```

### Bars

[](#bars)

```
echo $rating->render('html', ['type' => 'bars']);
```

### JSON Output

[](#json-output)

```
echo $rating->render('json');
// {
//   "average": 3.67,
//   "total": 150,
//   "distribution": {
//     "one_star": 6.67,
//     "two_star": 13.33,
//     ...
//   }
// }
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Templates

[](#custom-templates)

```
// Create custom template at path/to/template.php
echo $rating->render('html', [
    'template' => 'path/to/template.php'
]);
```

### Using in Frameworks

[](#using-in-frameworks)

**Laravel:**

```
// In controller
public function show(Product $product)
{
    return view('products.show', [
        'rating' => new \SimRating\Rating($product->ratings)
    ]);
}

// In Blade
{!! $rating->render() !!}
```

**Symfony:**

```
// In controller
public function show(Product $product): Response
{
    return $this->render('product/show.html.twig', [
        'rating' => new \SimRating\Rating($product->getRatings())
    ]);
}

// In Twig
{{ rating.render()|raw }}
```

**CodeIgniter 4:**

```
// In your Controller:
public function showProduct($productId)
{
    $productModel = new \App\Models\ProductModel();
    $product = $productModel->find($productId);

    $rating = new \Emleons\SimRating\Rating($product['ratings'], [
        'color' => '#f39c12',
        'size' => '1.5rem'
    ]);

    return view('product_view', [
        'product' => $product,
        'ratingStars' => $rating->render('html')
    ]);
}

// In your View (PHP syntax):

     average ( ratings)

// Or in Blade-style syntax if using CodeIgniter's View Decorator:

    {!! $ratingStars !!}
    {{ number_format($rating->getAverage(), 1) }} average ({{ $rating->getTotal() }} ratings)

```

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please open an issue or submit a pull request.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance56

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

293d ago

Major Versions

v1.1.1 → v2.1.12025-07-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/b331e86b72def00f61cf1913a0b6bb99d2ebeb4e61cdacfe7c436e6ea9d9b7bb?d=identicon)[EmLeons](/maintainers/EmLeons)

---

Top Contributors

[![emleonstz](https://avatars.githubusercontent.com/u/64161260?v=4)](https://github.com/emleonstz "emleonstz (2 commits)")

---

Tags

ratingrating-barrating-systemratings-stars

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emleons-sim-rating/health.svg)

```
[![Health](https://phpackages.com/badges/emleons-sim-rating/health.svg)](https://phpackages.com/packages/emleons-sim-rating)
```

###  Alternatives

[webit/eval-math

EvalMath

28838.7k5](/packages/webit-eval-math)[jdrieghe/array-helpers

A collection of convenience methods to deal with arrays in php. Somewhat inspired by Laravel array helpers.

17468.7k2](/packages/jdrieghe-array-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
