Skip to content

Commit

Permalink
add PHP Framework stats
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Apr 11, 2019
1 parent 9eedcab commit b8d71ca
Show file tree
Hide file tree
Showing 16 changed files with 1,764 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: php

php: 7.3
php: '7.3'

install:
- composer install
Expand Down
6 changes: 5 additions & 1 deletion ecs.yaml
Expand Up @@ -10,7 +10,7 @@ services:
enable_each_parameter_and_return_inspection: true

Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
max_cognitive_complexity: 6
max_cognitive_complexity: 8

parameters:
skip:
Expand All @@ -20,3 +20,7 @@ parameters:
# exists since PHP 7.3, not before
Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer:
- 'tests/Posts/Year2018/Php73/Php73Test.php'

# mixed[] array redundancy
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff.MissingTraversableReturnTypeHintSpecification: ~
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff.MissingTraversableParameterTypeHintSpecification: ~
1,121 changes: 1,121 additions & 0 deletions source/_data/generated/php_framework_trends.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/_layouts/post.twig
Expand Up @@ -112,7 +112,7 @@

<a name="comments"></a>

{% include "_snippets/disqus_comments.twig" with { 'post': post } %}
{% include "_snippets/disqus_comments.twig" %}
</div>

<script id="dsq-count-scr" src="https://{{ disqus_shortname }}.disqus.com/count.js" async defer></script>
Expand Down
6 changes: 6 additions & 0 deletions source/_snippets/footer.twig
Expand Up @@ -19,6 +19,12 @@
</div>

<p>
<strong>
<a href="/php-framework-trends/">PHP FW Trends</a>
</strong>

<span class="pl-2 pr-2">•</span>

Build by <a href="/thank-you/">{{ contributors|length + 1 }} people</a>

<span class="pl-2 pr-2">•</span>
Expand Down
7 changes: 7 additions & 0 deletions source/assets/css/style.css
Expand Up @@ -585,3 +585,10 @@ table ul {
text-align: center;
font-size: 2em;
}

.thead-inverse th h3 {
color: #DDD;
margin: 0;
font-size: 2em;
line-height: 1.7em;
}
2 changes: 1 addition & 1 deletion source/contact.twig
Expand Up @@ -8,7 +8,7 @@ id: contact
<h1>{{ title }}</h1>

<p class="text-center bigger">
Let me invite you to a great coffee and let's see <strong>how we can help each other</strong> →
Let me invite you to a great coffee to see <strong>how can I help you</strong> →
</p>

<div class="row mt-4 mb-5 ml-sm-0 ml-md-5 " id="contact-points">
Expand Down
125 changes: 125 additions & 0 deletions source/php-framework-trends.twig
@@ -0,0 +1,125 @@
---
layout: "_layouts/default.twig"
title: "PHP Framework Trends"
id: trends
---

{% macro trend(value) %}
{% if value > 0 %}
<strong>
<span class="text-success">+ {{ value|number_format }} %</span>
</strong>
{% else %}
<span class="text-danger">- {{ value|number_format|abs }} %</span>
{% endif %}
{% endmacro %}

{# local macros must be imported, then use like "{{ macros.<X>() }}" #}
{% import _self as macros %}

<div class="container-fluid" id="blog">
<h1>{{ title }}</h1>

<p class="text-muted mb-4">Updated at {{ php_framework_trends.updated_at|date('j. n. H:i') }}</p>

<table class="table table-bordered">
<thead class="thead-inverse">
<tr>
<th class="text-center">
Framework
</th>
<th class="text-center">Monthly Average</th>
<th class="text-center">Yearly Total</th>
<th class="text-center">Year Trend</th>
</tr>
</thead>

{% for framework in php_framework_trends.vendors %}
<tr>
<th>
{{ framework.name }}
<span class="text-muted">
<small>
<a href="#{{ framework.name|webalize }}">Jump to packages</a>
</small>
</span>
</th>
<td class="text-center">
{{ framework.vendor_total_last_month|number_format }}
</td>
<td class="text-center">
{{ framework.vendor_total_last_year|number_format }}
</td>
<td class="text-center">
{{ macros.trend(framework.average_last_year_trend) }}
</td>
</tr>
{% endfor %}
</table>

<br>

{% for framework in php_framework_trends.vendors %}
<table class="table table-bordered" id="{{ framework.name|webalize }}">
<thead class="thead-inverse">
<tr>
<th colspan="4" class="text-center">
<h3>{{ framework.name }}</h3>
</th>
</tr>
<tr>
<th>Package</th>
<th class="text-center">
Last month Daily
</th>
<th class="text-center">
Total Last Year
</th>
<th class="text-center">
Trend Last Year
</th>
</tr>
</thead>
{% for package in framework.packages_data %}
<tr>
<th>
{{ package.package_name }}
<small class="text-muted">
<a href="https://packagist.org/packages/{{ package.package_name }}/stats">see downloads</a>
</small>
</th>

<td class="text-right">{{ package.last_month_average_daily_downloads|number_format }}</td>
<td class="text-right">{{ package.last_year_total|number_format }}</td>
<td class="text-right">{{ macros.trend(package.last_year_trend) }}</td>
</tr>
{% endfor %}
</table>

<br>
<br>
{% endfor %}

<h2 class="mb-4">Methodology Notes</h2>

<p>Few outlier packages were removed to make numbers more relevant:</p>

<ul>
<li>
packages with <strong>less than 1000 downloads</strong> - not relevant compared in this scale

<ul>
<li>this limit was not passed by CodeIgniter, so it's excluded for now</li>
</ul>
</li>
<li>packages with <strong>history shorter than 12 months</strong> - they created extreme trends</li>
<li>packages with <strong>year trend bigger than 1000 %</strong> - they're caused by "hype" effect, that distorted average vendor trend</li>
<li><code>phpstan/phpstan</code> and <code>friendsofphp/php-cs-fixer</code> downloads are cleaned from statistics to prevent miss-leading numbers</li>
</ul>

<br>

<h2>What Do You Think?</h2>

{% include "_snippets/disqus_comments.twig" %}
</div>
34 changes: 34 additions & 0 deletions src/ArrayUtils.php
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace TomasVotruba\Website;

final class ArrayUtils
{
/**
* @param mixed[] $packagesData
*/
public function getArrayKeyAverage(array $packagesData, string $key): float
{
$total = [];
foreach ($packagesData as $packageData) {
$total[] = $packageData[$key];
}

$average = array_sum($total) / (count($total) ?: 1);

return round($average, 2);
}

/**
* @param mixed[] $array
*/
public function getArrayKeySum(array $array, string $key): int
{
$total = 0;
foreach ($array as $item) {
$total += (int) $item[$key];
}

return $total;
}
}

0 comments on commit b8d71ca

Please sign in to comment.